GCC Middle and Back End API Reference
tree-ssa-sink.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "tree.h"
#include "gimple.h"
#include "cfghooks.h"
#include "tree-pass.h"
#include "ssa.h"
#include "gimple-pretty-print.h"
#include "fold-const.h"
#include "stor-layout.h"
#include "cfganal.h"
#include "gimple-iterator.h"
#include "tree-cfg.h"
#include "cfgloop.h"
#include "tree-eh.h"
#include "tree-ssa-live.h"
Include dependency graph for tree-ssa-sink.cc:

Functions

static basic_block find_bb_for_arg (gphi *phi, tree def)
 
static bool all_immediate_uses_same_place (def_operand_p def_p)
 
static basic_block nearest_common_dominator_of_uses (def_operand_p def_p, bool *debug_stmts)
 
static bool do_not_sink (gimple *stmt, basic_block early_bb, basic_block best_bb)
 
static basic_block select_best_block (basic_block early_bb, basic_block late_bb, gimple *stmt)
 
static bool statement_sink_location (gimple *stmt, basic_block frombb, gimple_stmt_iterator *togsi, bool *zero_uses_p, virtual_operand_live &vop_live)
 
static unsigned sink_common_stores_to_bb (basic_block bb)
 
static unsigned sink_code_in_bb (basic_block bb, virtual_operand_live &vop_live)
 
gimple_opt_passmake_pass_sink_code (gcc::context *ctxt)
 

Variables

struct { 
 
   int   sunk 
 
   int   commoned 
 
sink_stats 
 

Function Documentation

◆ all_immediate_uses_same_place()

static bool all_immediate_uses_same_place ( def_operand_p def_p)
static
When the first immediate use is in a statement, then return true if all
immediate uses in IMM are in the same statement.
We could also do the case where  the first immediate use is in a phi node,
and all the other uses are in phis in the same basic block, but this
requires some expensive checking later (you have to make sure no def/vdef
in the statement occurs for multiple edges in the various phi nodes it's
used in, so that you only have one place you can sink it to.   

References DEF_FROM_PTR, FOR_EACH_IMM_USE_FAST, is_gimple_debug(), NULL, and USE_STMT.

Referenced by statement_sink_location().

◆ do_not_sink()

static bool do_not_sink ( gimple * stmt,
basic_block early_bb,
basic_block best_bb )
static

◆ find_bb_for_arg()

static basic_block find_bb_for_arg ( gphi * phi,
tree def )
static
Given a PHI, and one of its arguments (DEF), find the edge for
that argument and return it.  If the argument occurs twice in the PHI node,
we return NULL.   

References gimple_phi_arg_edge(), gimple_phi_num_args(), i, NULL, and PHI_ARG_DEF.

Referenced by statement_sink_location().

◆ make_pass_sink_code()

gimple_opt_pass * make_pass_sink_code ( gcc::context * ctxt)

◆ nearest_common_dominator_of_uses()

◆ select_best_block()

static basic_block select_best_block ( basic_block early_bb,
basic_block late_bb,
gimple * stmt )
static
Given EARLY_BB and LATE_BB, two blocks in a path through the dominator
tree, return the best basic block between them (inclusive) to place
statements.

We want the most control dependent block in the shallowest loop nest.

If the resulting block is in a shallower loop nest, then use it.   

References profile_probability::always(), bb_loop_depth(), CDI_DOMINATORS, CDI_POST_DOMINATORS, do_not_sink(), dominated_by_p(), gcc_checking_assert, get_immediate_dominator(), single_pred_edge(), and single_pred_p().

Referenced by statement_sink_location().

◆ sink_code_in_bb()

◆ sink_common_stores_to_bb()

◆ statement_sink_location()

Variable Documentation

◆ commoned

int commoned

◆ [struct]

struct { ... } sink_stats
Code sinking for trees
   Copyright (C) 2001-2024 Free Software Foundation, Inc.
   Contributed by Daniel Berlin <dan@dberlin.org>

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   
TODO:
1. Sinking store only using scalar promotion (IE without moving the RHS):

*q = p;
p = p + 1;
if (something)
  *q = <not p>;
else
  y = *q;


should become
sinktemp = p;
p = p + 1;
if (something)
  *q = <not p>;
else
{
  *q = sinktemp;
  y = *q
}
Store copy propagation will take care of the store elimination above.


2. Sinking using Partial Dead Code Elimination.   

Referenced by sink_code_in_bb(), and sink_common_stores_to_bb().

◆ sunk

int sunk

Referenced by sink_clobbers().