GCC Middle and Back End API Reference
tree-eh.c File Reference

Data Structures

union  treemple
struct  finally_tree_node
struct  finally_tree_hasher
struct  goto_queue_node
struct  leh_state
struct  leh_tf_state

Functions

static void add_stmt_to_eh_lp_fn ()
void add_stmt_to_eh_lp ()
static void record_stmt_eh_region ()
bool remove_stmt_from_eh_lp_fn ()
bool remove_stmt_from_eh_lp ()
int lookup_stmt_eh_lp_fn ()
int lookup_stmt_eh_lp ()
static void record_in_finally_tree ()
static void collect_finally_tree (gimple stmt, gimple region)
static void collect_finally_tree_1 ()
static void collect_finally_tree ()
static bool outside_finally_tree ()
static gimple_seq lower_eh_must_not_throw (struct leh_state *, gimple)
static void lower_eh_constructs_1 (struct leh_state *state, gimple_seq *seq)
static gimple_seq find_goto_replacement ()
static void replace_goto_queue_cond_clause (tree *tp, struct leh_tf_state *tf, gimple_stmt_iterator *gsi)
static void replace_goto_queue_stmt_list (gimple_seq *, struct leh_tf_state *)
static void replace_goto_queue_1 (gimple stmt, struct leh_tf_state *tf, gimple_stmt_iterator *gsi)
static void replace_goto_queue_stmt_list ()
static void replace_goto_queue ()
static void record_in_goto_queue (struct leh_tf_state *tf, treemple new_stmt, int index, bool is_label, location_t location)
static void record_in_goto_queue_label (struct leh_tf_state *tf, treemple stmt, tree label, location_t location)
static void maybe_record_in_goto_queue ()
static void verify_norecord_switch_expr ()
static void do_return_redirection ()
static void do_goto_redirection (struct goto_queue_node *q, tree finlab, gimple_seq mod, struct leh_tf_state *tf)
static void emit_post_landing_pad ()
static void emit_resx ()
static void emit_eh_dispatch ()
static void note_eh_region_may_contain_throw ()
static bool eh_region_may_contain_throw ()
static gimple_seq frob_into_branch_around ()
static gimple_seq lower_try_finally_dup_block (gimple_seq seq, struct leh_state *outer_state, location_t loc)
static tree lower_try_finally_fallthru_label ()
static gimple get_eh_else ()
static void honor_protect_cleanup_actions (struct leh_state *outer_state, struct leh_state *this_state, struct leh_tf_state *tf)
static void lower_try_finally_nofallthru (struct leh_state *state, struct leh_tf_state *tf)
static void lower_try_finally_onedest ()
static void lower_try_finally_copy ()
static void lower_try_finally_switch ()
static bool decide_copy_try_finally ()
static bool cleanup_is_dead_in ()
static gimple_seq lower_try_finally ()
static gimple_seq lower_catch ()
static gimple_seq lower_eh_filter ()
static gimple_seq lower_eh_must_not_throw ()
static gimple_seq lower_cleanup ()
static void lower_eh_constructs_2 ()
static void lower_eh_constructs_1 ()
static unsigned int lower_eh_constructs ()
gimple_opt_passmake_pass_lower_eh ()
bool make_eh_dispatch_edges ()
void make_eh_edges ()
static void redirect_eh_edge_1 ()
edge redirect_eh_edge ()
void redirect_eh_dispatch_edge ()
bool operation_could_trap_helper_p (enum tree_code op, bool fp_operation, bool honor_trapv, bool honor_nans, bool honor_snans, tree divisor, bool *handled)
bool operation_could_trap_p (enum tree_code op, bool fp_operation, bool honor_trapv, tree divisor)
bool tree_could_trap_p ()
static bool stmt_could_throw_1_p ()
bool stmt_could_throw_p ()
bool tree_could_throw_p ()
bool stmt_can_throw_external ()
bool stmt_can_throw_internal ()
bool maybe_clean_eh_stmt_fn ()
bool maybe_clean_eh_stmt ()
bool maybe_clean_or_replace_eh_stmt ()
bool maybe_duplicate_eh_stmt_fn (struct function *new_fun, gimple new_stmt, struct function *old_fun, gimple old_stmt, struct pointer_map_t *map, int default_lp_nr)
bool maybe_duplicate_eh_stmt ()
static bool same_handler_p ()
static void optimize_double_finally ()
static void refactor_eh_r ()
static unsigned refactor_eh ()
static bool gate_refactor_eh ()
gimple_opt_passmake_pass_refactor_eh ()
static bool lower_resx ()
static unsigned execute_lower_resx ()
static bool gate_lower_resx ()
gimple_opt_passmake_pass_lower_resx ()
static void optimize_clobbers ()
static int sink_clobbers ()
static bool lower_eh_dispatch ()
static unsigned execute_lower_eh_dispatch ()
static bool gate_lower_eh_dispatch ()
gimple_opt_passmake_pass_lower_eh_dispatch ()
static void mark_reachable_handlers ()
static void remove_unreachable_handlers ()
void maybe_remove_unreachable_handlers ()
static void remove_unreachable_handlers_no_lp ()
static bool unsplit_eh ()
static bool unsplit_all_eh ()
static bool cleanup_empty_eh_merge_phis (basic_block new_bb, basic_block old_bb, edge old_bb_out, bool change_region)
static void cleanup_empty_eh_move_lp (basic_block bb, edge e_out, eh_landing_pad lp, eh_region new_region)
static bool cleanup_empty_eh_unsplit ()
static bool infinite_empty_loop_p ()
static bool cleanup_empty_eh ()
static bool cleanup_all_empty_eh ()
static unsigned int execute_cleanup_eh_1 ()
static unsigned int execute_cleanup_eh ()
static bool gate_cleanup_eh ()
gimple_opt_passmake_pass_cleanup_eh ()
DEBUG_FUNCTION bool verify_eh_edges ()
DEBUG_FUNCTION bool verify_eh_dispatch_edge ()

Variables

static hash_table
< finally_tree_hasher
finally_tree
static gimple_seq eh_seq
static bitmap eh_region_may_contain_throw_map

Function Documentation

void add_stmt_to_eh_lp ( )
   Add statement T in the current function (cfun) to EH landing pad NUM.  

References add_stmt_to_eh_lp_fn(), cfun, ERT_MUST_NOT_THROW, eh_region_d::index, and eh_region_d::type.

static void add_stmt_to_eh_lp_fn ( )
static
   Misc functions used in this file.  
   Remember and lookup EH landing pad data for arbitrary statements.
   Really this means any statement that could_throw_p.  We could
   stuff this information into the stmt_ann data structure, but:

   (1) We absolutely rely on this information being kept until
   we get to rtl.  Once we're done with lowering here, if we lose
   the information there's no way to recover it!

   (2) There are many more statements that *cannot* throw as
   compared to those that can.  We should be saving some amount
   of space by only allocating memory for those that can throw.  
   Add statement T in function IFUN to landing pad NUM.  

Referenced by add_stmt_to_eh_lp(), and record_stmt_eh_region().

static bool cleanup_all_empty_eh ( )
static
   Do a post-order traversal of the EH region tree.  Examine each
   post_landing_pad block and see if we can eliminate it as empty.  

Referenced by cleanup_empty_eh_unsplit().

static bool cleanup_empty_eh ( )
static
   Examine the block associated with LP to determine if it's an empty
   handler for its EH region.  If so, attempt to redirect EH edges to
   an outer region.  Return true the CFG was updated in any way.  This
   is similar to jump forwarding, just across EH edges.  
     There can be zero or one edges out of BB.  This is the quickest test.  
     Make sure to skip debug statements.  
     If the block is totally empty, look for more unsplitting cases.  
         For the degenerate case of an infinite loop bail out.  
     The block should consist only of a single RESX statement, modulo a
     preceding call to __builtin_stack_restore if there is no outgoing
     edge, since the call can be eliminated in this case.  
     Determine if there are non-EH edges, or resx edges into the handler.  
     Find the handler that's outer of the empty handler by looking at
     where the RESX instruction was vectored.  
     If there's no destination region within the current function,
     redirection is trivial via removing the throwing statements from
     the EH region, removing the EH edges, and allowing the block
     to go unreachable.  
     If the destination region is a MUST_NOT_THROW, allow the runtime
     to handle the abort and allow the blocks to go unreachable.  
     Try to redirect the EH edges and merge the PHIs into the destination
     landing pad block.  If the merge succeeds, we'll already have redirected
     all the EH edges.  The handler itself will go unreachable if there were
     no normal edges.  
     Finally, if all input edges are EH edges, then we can (potentially)
     reduce the number of transfers from the runtime by moving the landing
     pad from the original region to the new region.  This is a win when
     we remove the last CLEANUP region along a particular exception
     propagation path.  Since nothing changes except for the region with
     which the landing pad is associated, the PHI nodes do not need to be
     adjusted at all.  
         ??? The CFG didn't change, but we may have rendered the
         old EH region unreachable.  Trigger a cleanup there.  
static bool cleanup_empty_eh_merge_phis ( basic_block  new_bb,
basic_block  old_bb,
edge  old_bb_out,
bool  change_region 
)
static
   A subroutine of cleanup_empty_eh.  Redirect all EH edges incoming
   to OLD_BB to NEW_BB; return true on success, false on failure.

   OLD_BB_OUT is the edge into NEW_BB from OLD_BB, so if we miss any
   PHI variables from OLD_BB we can pick them up from OLD_BB_OUT.
   Virtual PHIs may be deleted and marked for renaming.  
     The destination block must not be a regular successor for any
     of the preds of the landing pad.  Thus, avoid turning
        <..>
         |  \ EH
         |  <..>
         |  /
        <..>
     into
        <..>
        |  | EH
        <..>
     which CFG verification would choke on.  See PR45172 and PR51089.  
     First, iterate through the PHIs on NEW_BB and set up the edge_var_map
     for the edges we're going to move.  
         Find the corresponding PHI in OLD_BB so we can forward-propagate
         the source ssa_name.  
         If we did find the corresponding PHI, copy those inputs.  
             If NOP is used somewhere else beyond phis in new_bb, give up.  
         If we didn't find the PHI, if it's a real variable or a VOP, we know
         from the fact that OLD_BB is tree_empty_eh_handler_p that the
         variable is unchanged from input to the block and we can simply
         re-use the input to NEW_BB from the OLD_BB_OUT edge.  
     Second, verify that all PHIs from OLD_BB have been handled.  If not,
     we don't know what values from the other edges into NEW_BB to use.  
     Finally, move the edges and update the PHIs.  
           ???  CFG manipluation routines do not try to update loop
           form on edge redirection.  Do so manually here for now.  
           If we redirect a loop entry or latch edge that will either create
           a multiple entry loop or rotate the loop.  If the loops merge
           we may have created a loop with multiple latches.
           All of this isn't easily fixed thus cancel the affected loop
           and mark the other loop as possibly having multiple latches.  
static void cleanup_empty_eh_move_lp ( basic_block  bb,
edge  e_out,
eh_landing_pad  lp,
eh_region  new_region 
)
static
   A subroutine of cleanup_empty_eh.  Move a landing pad LP from its
   old region to NEW_REGION at BB.  
     Delete the RESX that was matched within the empty handler block.  
     Clean up E_OUT for the fallthru.  
static bool cleanup_empty_eh_unsplit ( )
static
   A subroutine of cleanup_empty_eh.  Handle more complex cases of
   unsplitting than unsplit_eh was prepared to handle, e.g. when
   multiple incoming edges and phis are involved.  
     We really ought not have totally lost everything following
     a landing pad label.  Given that BB is empty, there had better
     be a successor.  
     The destination block must not already have a landing pad
     for a different region.  
     Attempt to move the PHIs into the successor block.  

References CDI_DOMINATORS, CDI_POST_DOMINATORS, cfun, cleanup_all_empty_eh(), delete_unreachable_blocks(), function::eh, free_dominance_info(), eh_status::region_tree, remove_unreachable_handlers(), remove_unreachable_handlers_no_lp(), and unsplit_all_eh().

static bool cleanup_is_dead_in ( )
static
   REG is the enclosing region for a possible cleanup region, or the region
   itself.  Returns TRUE if such a region would be unreachable.

   Cleanup regions within a must-not-throw region aren't actually reachable
   even if there are throwing stmts within them, because the personality
   routine will call terminate before unwinding.  
static void collect_finally_tree ( gimple  stmt,
gimple  region 
)
static

Referenced by record_in_finally_tree().

static void collect_finally_tree ( )
static
         A type, a decl, or some kind of statement that we're not
         interested in.  Don't walk them.  
static void collect_finally_tree_1 ( )
static
   Go through the gimple sequence.  Works with collect_finally_tree to
   record all GIMPLE_LABEL and GIMPLE_TRY statements. 
static bool decide_copy_try_finally ( )
static
   Decide whether or not we are going to duplicate the finally block.
   There are several considerations.

   First, if this is Java, then the finally block contains code
   written by the user.  It has line numbers associated with it,
   so duplicating the block means it's difficult to set a breakpoint.
   Since controlling code generation via -g is verboten, we simply
   never duplicate code without optimization.

   Second, we'd like to prevent egregious code growth.  One way to
   do this is to estimate the size of the finally block, multiply
   that by the number of copies we'd need to make, and compare against
   the estimate of the size of the switch machinery we'd have to add.  
     If there's an EH_ELSE involved, the exception path is separate
     and really doesn't come into play for this computation.  
     Finally estimate N times, plus N gotos.  
     Switch statement (cost 10), N variable assignments, N gotos.  
     Optimize for size clearly wants our best guess.  
     ??? These numbers are completely made up so far.  
static void do_goto_redirection ( struct goto_queue_node q,
tree  finlab,
gimple_seq  mod,
struct leh_tf_state tf 
)
static
   Similar, but easier, for GIMPLE_GOTO.  

References bitmap_set_bit(), ERT_MUST_NOT_THROW, eh_region_d::index, eh_region_d::outer, and eh_region_d::type.

Referenced by honor_protect_cleanup_actions().

static void do_return_redirection ( )
static
   Redirect a RETURN_EXPR pointed to by Q to FINLAB.  If MOD is
   non-null, insert it before the new branch.  
     In the case of a return, the queue node must be a gimple statement.  
     Note that the return value may have already been computed, e.g.,

        int x;
        int foo (void)
        {
          x = 0;
          try {
            return x;
          } finally {
            x++;
          }
        }

     should return 0, not 1.  We don't have to do anything to make
     this happens because the return value has been placed in the
     RESULT_DECL already.  

References create_artificial_label(), gen_eh_landing_pad(), gimple_build_label(), gimple_seq_add_stmt(), eh_landing_pad_d::index, eh_region_d::landing_pads, and eh_landing_pad_d::post_landing_pad.

Referenced by honor_protect_cleanup_actions().

static bool eh_region_may_contain_throw ( )
inlinestatic
   Check if REGION has been marked as containing a throw.  If REGION is
   NULL, this predicate is false.  
static void emit_eh_dispatch ( )
static
   Emit an EH_DISPATCH statement into SEQ for REGION.  
static void emit_post_landing_pad ( )
static
   Emit a standard landing pad sequence into SEQ for REGION.  

Referenced by honor_protect_cleanup_actions().

static void emit_resx ( )
static
   Emit a RESX statement into SEQ for REGION.  
static unsigned int execute_cleanup_eh ( )
static
     If the function no longer needs an EH personality routine
     clear it.  This exposes cross-language inlining opportunities
     and avoids references to a never defined personality routine.  
static unsigned int execute_cleanup_eh_1 ( )
static
@verbatim 

Perform cleanups and lowering of exception handling 1) cleanups regions with handlers doing nothing are optimized out 2) MUST_NOT_THROW regions that became dead because of 1) are optimized out 3) Info about regions that are containing instructions, and regions reachable via local EH edges is collected 4) Eh tree is pruned for regions no longer necessary.

TODO: Push MUST_NOT_THROW regions to the root of the EH tree. Unify those that have the same failure decl and locus.

     Do this first: unsplit_all_eh and cleanup_all_empty_eh can die
     looking up unreachable landing pads.  
     Watch out for the region tree vanishing due to all unreachable.  
             We delayed all basic block deletion, as we may have performed
             cleanups on EH edges while non-EH edges were still present.  
             We manipulated the landing pads.  Remove any region that no
             longer has a landing pad.  
static unsigned execute_lower_eh_dispatch ( )
static
static unsigned execute_lower_resx ( )
static
static gimple_seq find_goto_replacement ( )
static
static gimple_seq frob_into_branch_around ( )
static
   We want to transform
        try { body; } catch { stuff; }
   to
        normal_seqence:
          body;
          over:
        eh_seqence:
          landing_pad:
          stuff;
          goto over;

   TP is a GIMPLE_TRY node.  REGION is the region whose post_landing_pad
   should be placed before the second operand, or NULL.  OVER is
   an existing label that should be put at the exit, or NULL.  

References create_artificial_label(), leh_tf_state::fallthru_label, gimple_location(), leh_tf_state::outer, record_in_finally_tree(), treemple::t, leh_state::tf, and leh_tf_state::try_finally_expr.

static bool gate_cleanup_eh ( )
static
static bool gate_lower_eh_dispatch ( )
static
static bool gate_lower_resx ( )
static

References gimple_vdef().

static bool gate_refactor_eh ( )
static
static gimple get_eh_else ( )
inlinestatic
   A subroutine of lower_try_finally.  If FINALLY consits of a
   GIMPLE_EH_ELSE node, return it.  

Referenced by honor_protect_cleanup_actions().

static void honor_protect_cleanup_actions ( struct leh_state outer_state,
struct leh_state this_state,
struct leh_tf_state tf 
)
static
   A subroutine of lower_try_finally.  If the eh_protect_cleanup_actions
   langhook returns non-null, then the language requires that the exception
   path out of a try_finally be treated specially.  To wit: the code within
   the finally block may not itself throw an exception.  We have two choices
   here. First we can duplicate the finally block and wrap it in a
   must_not_throw region.  Second, we can generate code like

        try {
          finally_block;
        } catch {
          if (fintmp == eh_edge)
            protect_cleanup_actions;
        }

   where "fintmp" is the temporary used in the switch statement generation
   alternative considered below.  For the nonce, we always choose the first
   option.

   THIS_STATE may be null if this is a try-cleanup, not a try-finally.  
     First check for nothing to do.  
     Duplicate the FINALLY block.  Only need to do this for try-finally,
     and not for cleanups.  If we've got an EH_ELSE, extract it now.  
     If this cleanup consists of a TRY_CATCH_EXPR with TRY_CATCH_IS_CLEANUP
     set, the handler of the TRY_CATCH_EXPR is another cleanup which ought
     to be in an enclosing scope, but needs to be implemented at this level
     to avoid a nesting violation (see wrap_temporary_cleanups in
     cp/decl.c).  Since it's logically at an outer level, we should call
     terminate before we get to it, so strip it away before adding the
     MUST_NOT_THROW filter.  
     Wrap the block with protect_cleanup_actions as the action.  
     Drop all of this into the exception sequence.  
     Having now been handled, EH isn't to be considered with
     the rest of the outgoing edges.  

References create_artificial_label(), do_goto_redirection(), do_return_redirection(), emit_post_landing_pad(), get_eh_else(), gimple_build_goto(), gimple_build_label(), gimple_eh_else_e_body(), gimple_eh_else_n_body(), gimple_location(), gimple_seq_add_seq(), gimple_seq_add_stmt(), gimple_set_location(), gimple_try_cleanup(), gimple_try_eval(), leh_tf_state::goto_queue, leh_tf_state::goto_queue_active, goto_queue_node::index, lower_eh_constructs_1(), leh_tf_state::may_throw, leh_tf_state::region, replace_goto_queue(), leh_tf_state::top_p, leh_tf_state::top_p_seq, and leh_tf_state::try_finally_expr.

static bool infinite_empty_loop_p ( )
static
   Return true if edge E_FIRST is part of an empty infinite loop
   or leads to such a loop through a series of single successor
   empty bbs.  
int lookup_stmt_eh_lp ( )
   Likewise, but always use the current function.  
     We can get called from initialized data when -fnon-call-exceptions
     is on; prevent crash.  

References finally_tree_node::child, and finally_tree_node::parent.

Referenced by lower_eh_constructs().

int lookup_stmt_eh_lp_fn ( )
   Determine if statement T is inside an EH region in function IFUN.
   Positive numbers indicate a landing pad index; negative numbers
   indicate a MUST_NOT_THROW region index; zero indicates that the
   statement is not recorded in the region table.  

Referenced by move_stmt_op().

static gimple_seq lower_catch ( )
static
   A subroutine of lower_eh_constructs_1.  Lower a GIMPLE_TRY_CATCH with a
   list of GIMPLE_CATCH to a sequence of labels and blocks, plus the
   exception region trees that records all the magic.  
static gimple_seq lower_cleanup ( )
static
   Implement a cleanup expression.  This is similar to try-finally,
   except that we only execute the cleanup block for exception edges.  
     Build enough of a try-finally state so that we can reuse
     honor_protect_cleanup_actions.  
         In this case honor_protect_cleanup_actions had nothing to do,
         and we should process this normally.  
         In this case honor_protect_cleanup_actions did nearly all of
         the work.  All we have left is to append the fallthru_label.  
static unsigned int lower_eh_constructs ( )
static
     We assume there's a return statement, or something, at the end of
     the function, and thus ploping the EH sequence afterward won't
     change anything.  
     We assume that since BODYP already existed, adding EH_SEQ to it
     didn't change its value, and we don't have to re-set the function.  
     If this function needs a language specific EH personality routine
     and the frontend didn't already set one do so now.  

References edge_def::dest, edge_def::flags, gen_eh_landing_pad(), get_eh_landing_pad_from_number(), gimple_block_label(), eh_landing_pad_d::index, last_stmt(), lookup_stmt_eh_lp(), eh_landing_pad_d::post_landing_pad, basic_block_def::preds, eh_landing_pad_d::region, remove_eh_landing_pad(), remove_stmt_from_eh_lp(), and edge_def::src.

static void lower_eh_constructs_1 ( struct leh_state state,
gimple_seq seq 
)
static
static void lower_eh_constructs_1 ( )
static
   A helper to unwrap a gimple_seq and feed stmts to lower_eh_constructs_2. 
static void lower_eh_constructs_2 ( )
static
   Main loop for lowering eh constructs. Also moves gsi to the next
   statement. 
                 The front end may have generated a call to
                 __builtin_eh_pointer (0) within a catch region.  Replace
                 this zero argument with the current catch region number.  
                     The user has dome something silly.  Remove it.  
                 ??? This should never appear, but since it's a builtin it
                 is accessible to abuse by users.  Just remove it and
                 replace the use with the arbitrary value zero.  
                 FALLTHRU 
                 Likewise this should not appear.  Remove it.  
         FALLTHRU 
         If the stmt can throw use a new temporary for the assignment
         to a LHS.  This makes sure the old value of the LHS is
         available on the EH edge.  Only do so for statements that
         potentially fall through (no noreturn calls e.g.), otherwise
         this new assignment might create fake fallthru regions.  
         Look for things that can throw exceptions, and record them.  
                       This code is only valid with GIMPLE_TRY_FINALLY.  
         Remove the old stmt and insert the transformed sequence
         instead. 
         Return since we don't want gsi_next () 
         We should be eliminating this in lower_try_finally et al.  
         A type, a decl, or some kind of statement that we're not
         interested in.  Don't walk them.  
static bool lower_eh_dispatch ( )
static
   At the end of inlining, we can lower EH_DISPATCH.  Return true when 
   we have found some duplicate labels and removed some edges.  
           Collect the labels for a switch.  Zero the post_landing_pad
           field becase we'll no longer have anything keeping these labels
           in existence and the optimizer will be free to merge these
           blocks at will.  
                   Filter out duplicate labels that arise when this handler 
                   is shadowed by an earlier one.  When no labels are 
                   attached to the handler anymore, we remove 
                   the corresponding edge and then we delete unreachable 
                   blocks at the end of this pass.  
           Clean up the edge flags.  
                   If there was no catch-all, use the fallthru edge.  
           Don't generate a switch if there's only a default case.
           This is common in the form of try { A; } catch (...) { B; }.  
               Turn the default label into a default case.  
     Replace the EH_DISPATCH with the SWITCH or COND generated above.  
static gimple_seq lower_eh_filter ( )
static
   A subroutine of lower_eh_constructs_1.  Lower a GIMPLE_TRY with a
   GIMPLE_EH_FILTER to a sequence of labels and blocks, plus the exception
   region trees that record all the magic.  
static gimple_seq lower_eh_must_not_throw ( struct leh_state ,
gimple   
)
static
static gimple_seq lower_eh_must_not_throw ( )
static
   A subroutine of lower_eh_constructs_1.  Lower a GIMPLE_TRY with
   an GIMPLE_EH_MUST_NOT_THROW to a sequence of labels and blocks,
   plus the exception region trees that record all the magic.  
         In order to get mangling applied to this decl, we must mark it
         used now.  Otherwise, pass_ipa_free_lang_data won't think it
         needs to happen.  
static bool lower_resx ( )
static
   At the end of gimple optimization, we can lower RESX.  
         We can wind up with no source region when pass_cleanup_eh shows
         that there are no entries into an eh region and deletes it, but
         then the block that contains the resx isn't removed.  This can
         happen without optimization when the switch statement created by
         lower_try_finally_switch isn't simplified to remove the eh case.

         Resolve this by expanding the resx node to an abort.  
         When we have a destination region, we resolve this by copying
         the excptr and filter values into place, and changing the edge
         to immediately after the landing pad.  
             We are resuming into a MUST_NOT_CALL region.  Expand a call to
             the failure decl into a new block, if needed.  
             Update the flags for the outgoing edge.  
             If there are no more EH users of the landing pad, delete it.  
         When we don't have a destination region, this exception escapes
         up the call chain.  We resolve this by generating a call to the
         _Unwind_Resume library function.  
         The ARM EABI redefines _Unwind_Resume as __cxa_end_cleanup
         with no arguments for C++ and Java.  Check for that.  
static gimple_seq lower_try_finally ( )
static
   A subroutine of lower_eh_constructs_1.  Lower a GIMPLE_TRY_FINALLY nodes
   to a sequence of labels and blocks, plus the exception region trees
   that record all the magic.  This is complicated by the need to
   arrange for the FINALLY block to be executed on all exits.  
     Process the try block.  
     Determine if the try block is escaped through the bottom.  
     Determine if any exceptions are possible within the try block.  
     Determine how many edges (still) reach the finally block.  Or rather,
     how many destinations are reached by the finally block.  Use this to
     determine how we process the finally block itself.  
     If the FINALLY block is not reachable, dike it out.  
     If the finally block doesn't fall through, then any destination
     we might try to impose there isn't reached either.  There may be
     some minor amount of cleanup and redirection still needed.  
     We can easily special-case redirection to a single destination.  
     If someone requested we add a label at the end of the transformed
     block, do so.  
         This must be reached only if ndests == 0. 
     If there was an old (aka outer) eh_seq, append the current eh_seq.
     If there was no old eh_seq, then the append is trivially already done.  
static void lower_try_finally_copy ( )
static
   A subroutine of lower_try_finally.  There are multiple edges incoming
   and outgoing from the finally block.  Implement this by duplicating the
   finally block for every destination.  
     Notice EH_ELSE, and simplify some of the remaining code
     by considering FINALLY to be the normal return path only.  
         We don't need to copy the EH path of EH_ELSE,
         since it is only emitted once.  
     Need to link new stmts after running replace_goto_queue due
     to not wanting to process the same goto stmts twice.  
static gimple_seq lower_try_finally_dup_block ( gimple_seq  seq,
struct leh_state outer_state,
location_t  loc 
)
static
   A subroutine of lower_try_finally.  Duplicate the tree rooted at T.
   Make sure to record all new labels found.  

References lang_hooks::eh_protect_cleanup_actions.

static tree lower_try_finally_fallthru_label ( )
static
   A subroutine of lower_try_finally.  Create a fallthru label for
   the given try_finally state.  The only tricky bit here is that
   we have to make sure to record the label in our outer context.  
static void lower_try_finally_nofallthru ( struct leh_state state,
struct leh_tf_state tf 
)
static
   A subroutine of lower_try_finally.  We have determined that there is
   no fallthru edge out of the finally block.  This means that there is
   no outgoing edge corresponding to any incoming edge.  Restructure the
   try_finally node for this special case.  
     We expect that tf->top_p is a GIMPLE_TRY. 
     Emit the finally block into the stream.  Lower EH_ELSE at this time.  
static void lower_try_finally_onedest ( )
static
   A subroutine of lower_try_finally.  We have determined that there is
   exactly one destination of the finally block.  Restructure the
   try_finally node for this special case.  
     Since there's only one destination, and the destination edge can only
     either be EH or non-EH, that implies that all of our incoming edges
     are of the same type.  Therefore we can lower EH_ELSE immediately.  
         Only reachable via the exception edge.  Add the given label to
         the head of the FINALLY block.  Append a RESX at the end.  
         Only reachable via the fallthru edge.  Do nothing but let
         the two blocks run together; we'll fall out the bottom.  
         Reachable by return expressions only.  Redirect them.  
         Reachable by goto expressions only.  Redirect them.  
             Reachable by goto to fallthru label only.  Redirect it
             to the new label (already created, sadly), and do not
             emit the final branch out, or the fallthru label.  
     Place the original return/goto to the original destination
     immediately after the finally block. 

References leh_tf_state::fallthru_label.

static void lower_try_finally_switch ( )
static
   A subroutine of lower_try_finally.  There are multiple edges incoming
   and outgoing from the finally block.  Implement this by instrumenting
   each incoming edge and creating a switch statement at the end of the
   finally block that branches to the appropriate destination.  
     The location of the TRY_FINALLY stmt.  
     The location of the finally block.  
     Mash the TRY block to the head of the chain.  
     The location of the finally is either the last stmt in the finally
     block or the location of the TRY_FINALLY itself.  
     Lower the finally block itself.  
     Prepare for switch statement generation.  
     We use vec::quick_push on case_label_vec throughout this function,
     since we know the size in advance and allocate precisely as muce
     space as needed.  
     Begin inserting code for getting to the finally block.  Things
     are done in this order to correspond to the sequence the code is
     laid out.  
     For EH_ELSE, emit the exception path (plus resx) now, then
     subsequently we only need consider the normal path.  
     Redirect each incoming goto edge.  
     Prepare the assignments to finally_tmp that are executed upon the
     entrance through a particular edge. 
             We store the cont_stmt in the pointer map, so that we can recover
             it in the loop below.  
     Make sure that the last case is the default label, as one is required.
     Then sort the labels, which is also required in GIMPLE.  
     Build the switch statement, setting last_case to be the default
     label.  
     Need to link SWITCH_STMT after running replace_goto_queue
     due to not wanting to process the same goto stmts twice.  
bool make_eh_dispatch_edges ( )
   Create the multiple edges from an EH_DISPATCH statement to all of
   the possible handlers for its EH region.  Return true if there's
   no fallthru edge; false if there is.  
             A catch-all handler doesn't have a fallthru.  
void make_eh_edges ( )
   Create the single EH edge from STMT to its nearest landing pad,
   if there is such a landing pad within the current function.  
gimple_opt_pass* make_pass_cleanup_eh ( )
gimple_opt_pass* make_pass_lower_eh ( )
gimple_opt_pass* make_pass_lower_eh_dispatch ( )
gimple_opt_pass* make_pass_lower_resx ( )
gimple_opt_pass* make_pass_refactor_eh ( )
static void mark_reachable_handlers ( )
static
   Walk statements, see what regions and, optionally, landing pads
   are really referenced.
   
   Returns in R_REACHABLEP an sbitmap with bits set for reachable regions,
   and in LP_REACHABLE an sbitmap with bits set for reachable landing pads.

   Passing NULL for LP_REACHABLE is valid, in this case only reachable
   regions are marked.

   The caller is responsible for freeing the returned sbitmaps.  
                 Negative LP numbers are MUST_NOT_THROW regions which
                 are not considered BB enders.  
                 Positive LP numbers are real landing pads, and BB enders.  
             Avoid removing regions referenced from RESX/EH_DISPATCH.  

References get_eh_region_from_lp_number(), gimple_label_label(), gsi_stmt(), and eh_landing_pad_d::region.

bool maybe_clean_eh_stmt ( )
   Likewise, but always use the current function.  

Referenced by replace_phi_args_in().

bool maybe_clean_eh_stmt_fn ( )
   Given a statement STMT in IFUN, if STMT can no longer throw, then
   remove any entry it might have from the EH table.  Return true if
   any change was made.  
bool maybe_clean_or_replace_eh_stmt ( )
   Given a statement OLD_STMT and a new statement NEW_STMT that has replaced
   OLD_STMT in the function, remove OLD_STMT from the EH table and put NEW_STMT
   in the table if it should be in there.  Return TRUE if a replacement was
   done that my require an EH edge purge.  

Referenced by gsi_split_seq_before(), optimize_stmt(), and replace_phi_args_in().

bool maybe_duplicate_eh_stmt ( )
   Similar, but both OLD_STMT and NEW_STMT are within the current function,
   and thus no remapping is required.  

Referenced by gimple_redirect_edge_and_branch().

bool maybe_duplicate_eh_stmt_fn ( struct function new_fun,
gimple  new_stmt,
struct function old_fun,
gimple  old_stmt,
struct pointer_map_t map,
int  default_lp_nr 
)
   Given a statement OLD_STMT in OLD_FUN and a duplicate statement NEW_STMT
   in NEW_FUN, copy the EH table data from OLD_STMT to NEW_STMT.  The MAP
   operand is the return value of duplicate_eh_regions.  
static void maybe_record_in_goto_queue ( )
static
   For any GIMPLE_GOTO or GIMPLE_RETURN, decide whether it leaves a try_finally
   node, and if so record that fact in the goto queue associated with that
   try_finally node.  

References gimple_switch_label(), outside_finally_tree(), treemple::t, and leh_tf_state::try_finally_expr.

void maybe_remove_unreachable_handlers ( void  )
   Remove unreachable handlers if any landing pads have been removed after
   last ehcleanup pass (due to gimple_purge_dead_eh_edges).  
static void note_eh_region_may_contain_throw ( )
static
   Note that the current EH region may contain a throw, or a
   call to a function which itself may contain a throw.  
bool operation_could_trap_helper_p ( enum tree_code  op,
bool  fp_operation,
bool  honor_trapv,
bool  honor_nans,
bool  honor_snans,
tree  divisor,
bool *  handled 
)
   Helper function for operation_could_trap_p and stmt_could_throw_p.  
         Some floating point comparisons may trap.  
         Conversion of floating point might trap.  
         These operations don't trap with floating point.  
         Any floating arithmetic may trap.  
         Constructing an object cannot trap.  
         Any floating arithmetic may trap.  
bool operation_could_trap_p ( enum tree_code  op,
bool  fp_operation,
bool  honor_trapv,
tree  divisor 
)
   Return true if operation OP may trap.  FP_OPERATION is true if OP is applied
   on floating-point values.  HONOR_TRAPV is true if OP is applied on integer
   type operands that may trap.  If OP is a division operator, DIVISOR contains
   the value of the divisor.  
static void optimize_clobbers ( )
static
   Try to optimize var = {v} {CLOBBER} stmts followed just by
   external throw.  
     Only optimize anything if the bb contains at least one clobber,
     ends with resx (checked by caller), optionally contains some
     debug stmts or labels, or at most one __builtin_stack_restore
     call, and has an incoming EH edge.  
static void optimize_double_finally ( )
static
   Optimize
    try { A() } finally { try { ~B() } catch { ~A() } }
    try { ... } finally { ~A() }
   into
    try { A() } catch { ~B() }
    try { ~B() ... } finally { ~A() }

   This occurs frequently in C++, where A is a local variable and B is a
   temporary used in the initializer for A.  
static bool outside_finally_tree ( )
static
   Use the finally tree to determine if a jump from START to TARGET
   would leave the try_finally node that START lives in.  

References goto_queue_node::cont_stmt, goto_queue_node::location, goto_queue_node::repl_stmt, and goto_queue_node::stmt.

Referenced by maybe_record_in_goto_queue().

static void record_in_finally_tree ( )
static
static void record_in_goto_queue ( struct leh_tf_state tf,
treemple  new_stmt,
int  index,
bool  is_label,
location_t  location 
)
static
   Add a new record to the goto queue contained in TF. NEW_STMT is the
   data to be added, IS_LABEL indicates whether NEW_STMT is a label or
   a gimple return. 

References leh_tf_state::dest_array.

Referenced by record_in_goto_queue_label().

static void record_in_goto_queue_label ( struct leh_tf_state tf,
treemple  stmt,
tree  label,
location_t  location 
)
static
   Record the LABEL label in the goto queue contained in TF.
   TF is not null.  
     Computed and non-local gotos do not get processed.  Given
     their nature we can neither tell whether we've escaped the
     finally block nor redirect them if we knew.  
     No need to record gotos that don't leave the try block.  
     In the case of a GOTO we want to record the destination label,
     since with a GIMPLE_COND we have an easy access to the then/else
     labels. 

References treemple::g, gimple_cond_false_label(), gimple_cond_true_label(), gimple_goto_dest(), gimple_location(), gimple_op_ptr(), leh_tf_state::may_return, record_in_goto_queue(), leh_state::tf, and treemple::tp.

static void record_stmt_eh_region ( )
static
   Add statement T to the single EH landing pad in REGION.  

References add_stmt_to_eh_lp_fn(), cfun, gen_eh_landing_pad(), eh_landing_pad_d::index, eh_region_d::landing_pads, and eh_landing_pad_d::next_lp.

void redirect_eh_dispatch_edge ( )
   This is a subroutine of gimple_redirect_edge_and_branch.  Update the
   labels for redirecting a non-fallthru EH_DISPATCH edge E to NEW_BB.
   The actual edge update will happen in the caller.  
edge redirect_eh_edge ( )
   Redirect EH edge E to NEW_BB.  
static void redirect_eh_edge_1 ( )
static
   Do the work in redirecting EDGE_IN to NEW_BB within the EH region tree;
   do not actually perform the final edge redirection.

   CHANGE_REGION is true when we're being called from cleanup_empty_eh and
   we intend to change the destination EH region as well; this means
   EH_LANDING_PAD_NR must already be set on the destination block label.
   If false, we're being called from generic cfg manipulation code and we
   should preserve our place within the region tree.  
     Look for an existing region that might be using NEW_BB already.  
         Unless CHANGE_REGION is true, the new and old landing pad
         had better be associated with the same EH region.  
     Notice when we redirect the last EH edge away from OLD_BB.  
         NEW_LP already exists.  If there are still edges into OLD_LP,
         there's nothing to do with the EH tree.  If there are no more
         edges into OLD_LP, then we want to remove OLD_LP as it is unused.
         If CHANGE_REGION is true, then our caller is expecting to remove
         the landing pad.  
         No correct landing pad exists.  If there are no more edges
         into OLD_LP, then we can simply re-use the existing landing pad.
         Otherwise, we have to create a new landing pad.  
     Maybe move the throwing statement to the new region.  
static unsigned refactor_eh ( )
static
static void refactor_eh_r ( )
static
   Perform EH refactoring optimizations that are simpler to do when code
   flow has been lowered but EH structures haven't.  
bool remove_stmt_from_eh_lp ( )
   Remove statement T in the current function (cfun) from its
   EH landing pad.  

References throw_stmt_node::lp_nr, and throw_stmt_node::stmt.

Referenced by lower_eh_constructs().

bool remove_stmt_from_eh_lp_fn ( )
   Remove statement T in function IFUN from its EH landing pad.  
static void remove_unreachable_handlers ( )
static
   Remove unreachable handlers and unreachable landing pads.  

Referenced by cleanup_empty_eh_unsplit(), and execute_lower_eh_dispatch().

static void remove_unreachable_handlers_no_lp ( )
static
   Remove regions that do not have landing pads.  This assumes
   that remove_unreachable_handlers has already been run, and
   that we've just manipulated the landing pads since then.

   Preserve regions with landing pads and regions that prevent
   exceptions from propagating further, even if these regions
   are not reachable.  

Referenced by cleanup_empty_eh_unsplit().

static void replace_goto_queue ( )
static
   Replace all goto queue members.  

References goto_queue_node::index.

Referenced by honor_protect_cleanup_actions().

static void replace_goto_queue_1 ( gimple  stmt,
struct leh_tf_state tf,
gimple_stmt_iterator gsi 
)
static
         These won't have gotos in them.  
static void replace_goto_queue_cond_clause ( tree tp,
struct leh_tf_state tf,
gimple_stmt_iterator gsi 
)
static
   A subroutine of replace_goto_queue_1.  Handles the sub-clauses of a
   lowered GIMPLE_COND.  If, by chance, the replacement is a simple goto,
   then we can just splat it in, otherwise we add the new stmts immediately
   after the GIMPLE_COND and redirect.  
     Set the new label for the GIMPLE_COND 

References find_goto_replacement(), treemple::g, gimple_catch_handler_ptr(), gimple_eh_else_e_body_ptr(), gimple_eh_else_n_body_ptr(), gimple_eh_filter_failure_ptr(), gimple_op_ptr(), gimple_seq_copy(), gimple_try_cleanup_ptr(), gimple_try_eval_ptr(), gsi_insert_seq_before(), gsi_remove(), GSI_SAME_STMT, and replace_goto_queue_stmt_list().

static void replace_goto_queue_stmt_list ( gimple_seq ,
struct leh_tf_state  
)
static
   The real work of replace_goto_queue.  Returns with TSI updated to
   point to the next statement.  

Referenced by replace_goto_queue_cond_clause().

static void replace_goto_queue_stmt_list ( )
static
   A subroutine of replace_goto_queue.  Handles GIMPLE_SEQ.  
static bool same_handler_p ( )
static
   Returns TRUE if oneh and twoh are exception handlers (gimple_try_cleanup of
   GIMPLE_TRY) that are similar enough to be considered the same.  Currently
   this only handles handlers consisting of a single call, as that's the
   important case for C++: a destructor call for a particular object showing
   up in multiple handlers.  
static int sink_clobbers ( )
static
   Try to sink var = {v} {CLOBBER} stmts followed just by
   internal throw to successor BB.  
     Only optimize if BB has a single EH successor and
     all predecessor edges are EH too.  
     And BB contains only CLOBBER stmts before the final
     RESX.  
     See if there is a virtual PHI node to take an updated virtual
     operand from.  
         Unfortunately we don't have dominance info updated at this
         point, so checking if
         dominated_by_p (CDI_DOMINATORS, succbb,
                         gimple_bb (SSA_NAME_DEF_STMT (TREE_OPERAND (lhs, 0)))
         would be too costly.  Thus, avoid sinking any clobbers that
         refer to non-(D) SSA_NAMEs.  
         As we do not change stmt order when sinking across a
         forwarder edge we can keep virtual operands in place.  
         But adjust virtual operands if we sunk across a PHI node.  
             Adjust the incoming virtual operand.  
         If there isn't a single predecessor but no virtual PHI node
         arrange for virtual operands to be renamed.  
             In this case there will be no use of the VDEF of this stmt. 
             ???  Unless this is a secondary opportunity and we have not
             removed unreachable blocks yet, so we cannot assert this.  
             Which also means we will end up renaming too many times.  
bool stmt_can_throw_external ( )
   Return true if STMT can throw an exception that is not caught within
   the current function (CFUN).  

Referenced by disqualify_ops_if_throwing_stmt(), and special_builtin_state().

bool stmt_can_throw_internal ( )
   Return true if STMT can throw an exception that is caught within
   the current function (CFUN).  

Referenced by disqualify_base_of_expr(), and vect_finish_stmt_generation().

static bool stmt_could_throw_1_p ( )
static
   Helper for stmt_could_throw_p.  Return true if STMT (assumed to be a
   an assignment or a conditional) may throw.  
     Check if the main expression may trap.  
     If the expression does not trap, see if any of the individual operands may
     trap.  

Referenced by tree_could_trap_p().

bool stmt_could_throw_p ( )
   Return true if statement STMT could throw an exception.  
     The only statements that can throw an exception are assignments,
     conditionals, calls, resx, and asms.  

Referenced by compare_range_with_value(), do_partial_partial_insertion(), handle_pointer_plus(), and special_builtin_state().

bool tree_could_throw_p ( )
   Return true if expression T could throw an exception.  

Referenced by component_of(), refs_independent_p(), and special_builtin_state().

bool tree_could_trap_p ( )
   Return true if EXPR can trap, as in dereferencing an invalid pointer
   location or floating point arithmetic.  C.f. the rtl version, may_trap_p.
   This routine expects only GIMPLE lhs or rhs input.  
         Fallthru.  
         Assume that calls to weak functions may trap.  
         Assume that accesses to weak functions may trap, unless we know
         they are certainly defined in current TU or in some other
         LTO partition.  
         Assume that accesses to weak vars may trap, unless we know
         they are certainly defined in current TU or in some other
         LTO partition.  

References function::can_throw_non_call_exceptions, cfun, gimple_asm_volatile_p(), gimple_call_nothrow_p(), and stmt_could_throw_1_p().

Referenced by refs_independent_p().

static bool unsplit_all_eh ( )
static
static bool unsplit_eh ( )
static
   Undo critical edge splitting on an EH landing pad.  Earlier, we
   optimisticaly split all sorts of edges, including EH edges.  The
   optimization passes in between may not have needed them; if not,
   we should undo the split.

   Recognize this case by having one EH edge incoming to the BB and
   one normal edge outgoing; BB should be empty apart from the
   post_landing_pad label.

   Note that this is slightly different from the empty handler case
   handled by cleanup_empty_eh, in that the actual handler may yet
   have actual code but the landing pad has been separated from the
   handler.  As such, cleanup_empty_eh relies on this transformation
   having been done first.  
     Quickly check the edge counts on BB for singularity.  
     Input edge must be EH and output edge must be normal.  
     The block must be empty except for the labels and debug insns.  
     The destination block must not already have a landing pad
     for a different region.  
     The new destination block must not already be a destination of
     the source block, lest we merge fallthru and eh edges and get
     all sorts of confused.  
     ??? We can get degenerate phis due to cfg cleanups.  I would have
     thought this should have been cleaned up by a phicprop pass, but
     that doesn't appear to handle virtuals.  Propagate by hand.  
     Redirect the edge.  Since redirect_eh_edge_1 expects to be moving
     a successor edge, humor it.  But do the real CFG change with the
     predecessor of E_OUT in order to preserve the ordering of arguments
     to the PHI nodes in E_OUT->DEST.  
DEBUG_FUNCTION bool verify_eh_dispatch_edge ( )
   Similarly, but handle GIMPLE_EH_DISPATCH specifically.  
             A catch-all handler doesn't have a fallthru.  
DEBUG_FUNCTION bool verify_eh_edges ( )
   Verify that BB containing STMT as the last statement, has precisely the
   edge that make_eh_edges would create.  
static void verify_norecord_switch_expr ( )
static
   We do not process GIMPLE_SWITCHes for now.  As long as the original source
   was in fact structured, and we've not yet done jump threading, then none
   of the labels will leave outer GIMPLE_TRY_FINALLY nodes. Verify this.  

Variable Documentation

bitmap eh_region_may_contain_throw_map
static
   Record whether an EH region contains something that can throw,
   indexed by EH region number.  
gimple_seq eh_seq
static
   Second pass of EH node decomposition.  Actually transform the GIMPLE_TRY
   nodes into a set of gotos, magic labels, and eh regions.
   The eh region creation is straight-forward, but frobbing all the gotos
   and such into shape isn't.  
   The sequence into which we record all EH stuff.  This will be
   placed at the end of the function when we're all done.  
hash_table<finally_tree_hasher> finally_tree
static
   Note that this table is *not* marked GTY.  It is short-lived.