GCC Middle and Back End API Reference
postreload-gcse.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "target.h"
#include "rtl.h"
#include "tree.h"
#include "predict.h"
#include "df.h"
#include "memmodel.h"
#include "tm_p.h"
#include "insn-config.h"
#include "emit-rtl.h"
#include "recog.h"
#include "cfgrtl.h"
#include "profile.h"
#include "expr.h"
#include "tree-pass.h"
#include "dbgcnt.h"
#include "intl.h"
#include "gcse-common.h"
#include "gcse.h"
#include "regs.h"
#include "function-abi.h"
Include dependency graph for postreload-gcse.cc:

Data Structures

struct  expr
struct  expr_hasher
struct  occr
struct  unoccr
struct  modifies_mem
struct  [struct].stats

Macros

#define INSN_CUID(INSN)

Functions

static hashval_t hash_expr (rtx x, int *do_not_record_p)
static void alloc_mem (void)
static void free_mem (void)
static bool oprs_unchanged_p (rtx, rtx_insn *, bool)
static void record_last_reg_set_info (rtx_insn *, rtx)
static void record_last_reg_set_info_regno (rtx_insn *, int)
static void record_last_mem_set_info (rtx_insn *)
static void record_last_set_info (rtx, const_rtx, void *)
static void record_opr_changes (rtx_insn *)
static void find_mem_conflicts (rtx, const_rtx, void *)
static bool load_killed_in_block_p (int, rtx, bool)
static void reset_opr_set_tables (void)
static void insert_expr_in_table (rtx, rtx_insn *)
static struct exprlookup_expr_in_table (rtx)
static void dump_hash_table (FILE *)
static bool reg_killed_on_edge (rtx, edge)
static bool reg_used_on_edge (rtx, edge)
static rtx get_avail_load_store_reg (rtx_insn *)
static bool bb_has_well_behaved_predecessors (basic_block)
static struct occrget_bb_avail_insn (basic_block, struct occr *, int)
static void hash_scan_set (rtx_insn *)
static void compute_hash_table (void)
static void eliminate_partially_redundant_load (basic_block, rtx_insn *, struct expr *)
static void eliminate_partially_redundant_loads (void)
int dump_expr_hash_table_entry (expr **slot, FILE *file)
static bool reg_changed_after_insn_p (rtx x, int cuid)
int compute_expr_transp (expr **slot, FILE *dump_file)
int delete_redundant_insns_1 (expr **slot, void *data)
static void delete_redundant_insns (void)
static void gcse_after_reload_main (rtx f)
static void rest_of_handle_gcse2 (void)
rtl_opt_passmake_pass_gcse2 (gcc::context *ctxt)

Variables

static struct  stats
static hash_table< expr_hasher > * expr_table
static struct obstack expr_obstack
static struct obstack occr_obstack
static struct obstack unoccr_obstack
static int * reg_avail_info
static struct modifies_memmodifies_mem_list
static struct obstack modifies_mem_obstack
static struct modifies_memmodifies_mem_obstack_bottom
static int * uid_cuid
static bitmap modify_mem_list_set
static bitmap blocks_with_calls
static vec< rtx_insn * > * modify_mem_list
static vec< modify_pair > * canon_modify_mem_list
static sbitmaptransp
static int mems_conflict_p

Macro Definition Documentation

◆ INSN_CUID

#define INSN_CUID ( INSN)
Value:
(uid_cuid[INSN_UID (INSN)])
static int * uid_cuid
Definition postreload-gcse.cc:212
int INSN_UID(const_rtx insn)
Definition rtl.h:1461

Referenced by hash_scan_set(), load_killed_in_block_p(), oprs_unchanged_p(), record_last_reg_set_info(), and record_last_reg_set_info_regno().

Function Documentation

◆ alloc_mem()

◆ bb_has_well_behaved_predecessors()

bool bb_has_well_behaved_predecessors ( basic_block bb)
static

◆ compute_expr_transp()

int compute_expr_transp ( expr ** slot,
FILE * dump_file )

◆ compute_hash_table()

void compute_hash_table ( void )
static
Create hash table of memory expressions available at end of basic
blocks.  Basically you should think of this hash table as the
representation of AVAIL_OUT.  This is the set of expressions that
is generated in a basic block and not killed before the end of the
same basic block.  Notice that this is really a local computation.   

References cfun, compute_hash_table(), FOR_BB_INSNS, FOR_EACH_BB_FN, GET_CODE, hash_scan_set(), modifies_mem::insn, INSN_P, PATTERN(), record_opr_changes(), reset_opr_set_tables(), and SET.

Referenced by compute_hash_table(), and gcse_after_reload_main().

◆ delete_redundant_insns()

void delete_redundant_insns ( void )
static

◆ delete_redundant_insns_1()

int delete_redundant_insns_1 ( expr ** slot,
void * data )
Go over the expression hash table and delete insns that were
marked for later deletion.   
This helper is called via htab_traverse.   

References expr::avail_occr, dbg_cnt(), delete_insn(), delete_redundant_insns_1(), occr::deleted_p, dump_file, occr::insn, occr::next, NULL, and print_rtl_single().

Referenced by delete_redundant_insns(), and delete_redundant_insns_1().

◆ dump_expr_hash_table_entry()

int dump_expr_hash_table_entry ( expr ** slot,
FILE * file )
Dump all expressions and occurrences that are currently in the
expression hash table to FILE.   
This helper is called via htab_traverse.   

References expr::avail_occr, dump_expr_hash_table_entry(), expr::expr, expr::hash, occr::insn, occr::next, print_rtl(), and print_rtl_single().

Referenced by dump_expr_hash_table_entry(), and dump_hash_table().

◆ dump_hash_table()

void dump_hash_table ( FILE * file)
static

◆ eliminate_partially_redundant_load()

void eliminate_partially_redundant_load ( basic_block bb,
rtx_insn * insn,
struct expr * expr )
static
The work horses of this pass.   
This handles the case where several stores feed a partially redundant
load. It checks if the redundancy elimination is possible and if it's
worth it.

Redundancy elimination is possible if,
1) None of the operands of an insn have been modified since the start
   of the current basic block.
2) In any predecessor of the current basic block, the same expression
   is generated.

See the function body for the heuristics that determine if eliminating
a redundancy is also worth doing, assuming it is possible.   

References expr::avail_occr, BB_END, BB_HEAD, expr::bitmap_index, BLOCK_FOR_INSN(), cfun, constrain_operands(), copy_insn(), copy_rtx(), delete_insn(), occr::deleted_p, dump_file, EDGE_CRITICAL_P, eliminate_partially_redundant_load(), extract_insn(), FOR_EACH_EDGE, gcc_assert, gen_move_insn(), get_avail_load_store_reg(), get_bb_avail_insn(), get_preferred_alternatives(), insert_insn_on_edge(), occr::insn, unoccr::insn, profile_count::max_count, occr::next, unoccr::next, NEXT_INSN(), NULL, NULL_RTX, optimize_bb_for_size_p(), PATTERN(), unoccr::pred, basic_block_def::preds, PREV_INSN(), print_rtl(), print_rtl_single(), profile_info, PROFILE_READ, profile_status_for_fn, reg_changed_after_insn_p(), reg_killed_on_edge(), reg_set_between_p(), reg_used_between_p(), reg_used_on_edge(), REGNO, SET_DEST, set_noop_p(), targetm, profile_count::to_gcov_type(), unoccr_obstack, and profile_count::zero().

Referenced by eliminate_partially_redundant_load(), and eliminate_partially_redundant_loads().

◆ eliminate_partially_redundant_loads()

◆ find_mem_conflicts()

void find_mem_conflicts ( rtx dest,
const_rtx setter,
void * data )
static
DEST is the output of an instruction.  If it is a memory reference, and
possibly conflicts with the load found in DATA, then set mems_conflict_p
to a nonzero value.   

References find_mem_conflicts(), GET_CODE, GET_MODE, MEM_P, mems_conflict_p, true_dependence(), and XEXP.

Referenced by find_mem_conflicts(), and load_killed_in_block_p().

◆ free_mem()

◆ gcse_after_reload_main()

◆ get_avail_load_store_reg()

rtx get_avail_load_store_reg ( rtx_insn * insn)
static
Return the loaded/stored register of a load/store instruction.   

References gcc_assert, get_avail_load_store_reg(), modifies_mem::insn, PATTERN(), REG_P, SET_DEST, and SET_SRC.

Referenced by eliminate_partially_redundant_load(), get_avail_load_store_reg(), and get_bb_avail_insn().

◆ get_bb_avail_insn()

◆ hash_expr()

hashval_t hash_expr ( rtx x,
int * do_not_record_p )
static
Hash expression X.
DO_NOT_RECORD_P is a boolean indicating if a volatile operand is found
or if the expression contains something we don't want to insert in the
table.   
Hash table support.   

References GET_MODE, hash_expr(), hash_rtx(), and NULL.

Referenced by hash_expr(), insert_expr_in_table(), and lookup_expr_in_table().

◆ hash_scan_set()

void hash_scan_set ( rtx_insn * insn)
static
Scan the pattern of INSN and add an entry to the hash TABLE.
After reload we are interested in loads/stores only.   

References can_copy_p(), FLOAT_MODE_P, general_operand(), GET_MODE, hash_scan_set(), insert_expr_in_table(), modifies_mem::insn, INSN_CUID, JUMP_P, load_killed_in_block_p(), MEM_P, oprs_unchanged_p(), PATTERN(), REG_P, REGNO, SET_DEST, set_noop_p(), SET_SRC, and XEXP.

Referenced by compute_hash_table(), and hash_scan_set().

◆ insert_expr_in_table()

void insert_expr_in_table ( rtx x,
rtx_insn * insn )
static
Insert expression X in INSN in the hash TABLE.
If it is already present, record it as the last occurrence in INSN's
basic block.   

References expr::avail_occr, expr::bitmap_index, BLOCK_FOR_INSN(), occr::deleted_p, expr::expr, expr_obstack, expr_table, expr::hash, hash_expr(), insert_expr_in_table(), occr::insn, occr::next, NULL, and occr_obstack.

Referenced by hash_scan_set(), and insert_expr_in_table().

◆ load_killed_in_block_p()

bool load_killed_in_block_p ( int uid_limit,
rtx x,
bool after_insn )
static
Return nonzero if the expression in X (a memory reference) is killed
in the current basic block before (if AFTER_INSN is false) or after
(if AFTER_INSN is true) the insn with the CUID in UID_LIMIT.

This function assumes that the modifies_mem table is flushed when
the hash table construction or redundancy elimination phases start
processing a new basic block.   

References CALL_P, find_mem_conflicts(), modifies_mem::insn, INSN_CUID, load_killed_in_block_p(), mems_conflict_p, modifies_mem_list, modifies_mem::next, and note_stores().

Referenced by hash_scan_set(), load_killed_in_block_p(), and oprs_unchanged_p().

◆ lookup_expr_in_table()

struct expr * lookup_expr_in_table ( rtx pat)
static
Lookup pattern PAT in the expression hash table.
The result is a pointer to the table entry, or NULL if not found.   

References expr::avail_occr, expr::expr, expr_obstack, expr_table, expr::hash, hash_expr(), lookup_expr_in_table(), and NULL.

Referenced by eliminate_partially_redundant_loads(), and lookup_expr_in_table().

◆ make_pass_gcse2()

rtl_opt_pass * make_pass_gcse2 ( gcc::context * ctxt)

◆ oprs_unchanged_p()

bool oprs_unchanged_p ( rtx x,
rtx_insn * insn,
bool after_insn )
static
Support for hash table construction and transformations.   
Return nonzero if the operands of expression X are unchanged
1) from the start of INSN's basic block up to but not including INSN
   if AFTER_INSN is false, or
2) from INSN to the end of INSN's basic block if AFTER_INSN is true.   

References CASE_CONST_ANY, gcc_assert, GET_CODE, GET_RTX_FORMAT, GET_RTX_LENGTH, i, occr::insn, INSN_CUID, load_killed_in_block_p(), oprs_unchanged_p(), reg_changed_after_insn_p(), REGNO, XEXP, XVECEXP, and XVECLEN.

Referenced by eliminate_partially_redundant_loads(), hash_scan_set(), and oprs_unchanged_p().

◆ record_last_mem_set_info()

void record_last_mem_set_info ( rtx_insn * insn)
static
Record memory modification information for INSN.  We do not actually care
about the memory location(s) that are set, or even how they are set (consider
a CALL_INSN).  We merely need to record which insns modify memory.   

References blocks_with_calls, canon_modify_mem_list, modifies_mem::insn, modifies_mem_list, modifies_mem_obstack, modify_mem_list, modify_mem_list_set, modifies_mem::next, record_last_mem_set_info(), and record_last_mem_set_info_common().

Referenced by record_last_mem_set_info(), record_last_set_info(), and record_opr_changes().

◆ record_last_reg_set_info()

void record_last_reg_set_info ( rtx_insn * insn,
rtx reg )
inlinestatic
Record register first/last/block set information for REGNO in INSN.   

References END_REGNO(), modifies_mem::insn, INSN_CUID, record_last_reg_set_info(), and REGNO.

Referenced by record_last_reg_set_info(), record_last_set_info(), and record_opr_changes().

◆ record_last_reg_set_info_regno()

void record_last_reg_set_info_regno ( rtx_insn * insn,
int regno )
inlinestatic

◆ record_last_set_info()

void record_last_set_info ( rtx dest,
const_rtx setter,
void * data )
static
Called from compute_hash_table via note_stores to handle one
SET or CLOBBER in an insn.  DATA is really the instruction in which
the SET is taking place.   

References GET_CODE, GET_MODE, MEM_P, push_operand(), record_last_mem_set_info(), record_last_reg_set_info(), record_last_reg_set_info_regno(), record_last_set_info(), REG_P, and SUBREG_REG.

Referenced by record_last_set_info(), and record_opr_changes().

◆ record_opr_changes()

◆ reg_changed_after_insn_p()

bool reg_changed_after_insn_p ( rtx x,
int cuid )
static
Return true if register X is recorded as being set by an instruction
whose CUID is greater than the one given.   

References END_REGNO(), reg_changed_after_insn_p(), and REGNO.

Referenced by eliminate_partially_redundant_load(), oprs_unchanged_p(), and reg_changed_after_insn_p().

◆ reg_killed_on_edge()

bool reg_killed_on_edge ( rtx reg,
edge e )
static
Helpers for eliminate_partially_redundant_load.   
Check if register REG is killed in any insn waiting to be inserted on
edge E.  This function is required to check that our data flow analysis
is still valid prior to commit_edge_insertions.   

References modifies_mem::insn, INSN_P, NEXT_INSN(), reg_killed_on_edge(), and reg_set_p().

Referenced by eliminate_partially_redundant_load(), get_bb_avail_insn(), and reg_killed_on_edge().

◆ reg_used_on_edge()

bool reg_used_on_edge ( rtx reg,
edge e )
static
Similar to above - check if register REG is used in any insn waiting
to be inserted on edge E.
Assumes no such insn can be a CALL_INSN; if so call reg_used_between_p
with PREV(insn),NEXT(insn) instead of calling reg_overlap_mentioned_p.   

References modifies_mem::insn, INSN_P, NEXT_INSN(), PATTERN(), reg_overlap_mentioned_p(), and reg_used_on_edge().

Referenced by eliminate_partially_redundant_load(), and reg_used_on_edge().

◆ reset_opr_set_tables()

void reset_opr_set_tables ( void )
static
Reset tables used to keep track of what's still available since the
start of the block.   

References modifies_mem_list, modifies_mem_obstack, modifies_mem_obstack_bottom, NULL, and reset_opr_set_tables().

Referenced by compute_hash_table(), eliminate_partially_redundant_loads(), and reset_opr_set_tables().

◆ rest_of_handle_gcse2()

void rest_of_handle_gcse2 ( void )
static

Variable Documentation

◆ blocks_with_calls

bitmap blocks_with_calls
static
Bitmap of blocks which have calls.   

Referenced by alloc_mem(), compute_expr_transp(), free_mem(), and record_last_mem_set_info().

◆ canon_modify_mem_list

vec<modify_pair>* canon_modify_mem_list
static
Vector indexed by block # with a canonicalized list of insns
that modify memory in the block.   

Referenced by alloc_mem(), compute_expr_transp(), free_mem(), and record_last_mem_set_info().

◆ expr_obstack

struct obstack expr_obstack
static

◆ expr_table

◆ mems_conflict_p

int mems_conflict_p
static
Used for communication between find_mem_conflicts and
load_killed_in_block_p.  Nonzero if find_mem_conflicts finds a
conflict between two memory references.
This is a bit of a hack to work around the limitations of note_stores.   

Referenced by find_mem_conflicts(), and load_killed_in_block_p().

◆ modifies_mem_list

struct modifies_mem* modifies_mem_list
static

◆ modifies_mem_obstack

struct obstack modifies_mem_obstack
static
The modifies_mem structs also go on an obstack, only this obstack is
freed each time after completing the analysis or transformations on
a basic block.  So we allocate a dummy modifies_mem_obstack_bottom
object on the obstack to keep track of the bottom of the obstack.   

Referenced by alloc_mem(), free_mem(), record_last_mem_set_info(), and reset_opr_set_tables().

◆ modifies_mem_obstack_bottom

struct modifies_mem* modifies_mem_obstack_bottom
static

Referenced by alloc_mem(), and reset_opr_set_tables().

◆ modify_mem_list

vec<rtx_insn *>* modify_mem_list
static
Vector indexed by block # with a list of all the insns that
modify memory within the block.   

Referenced by alloc_mem(), free_mem(), and record_last_mem_set_info().

◆ modify_mem_list_set

bitmap modify_mem_list_set
static
Bitmap of blocks which have memory stores.   

Referenced by alloc_mem(), compute_expr_transp(), free_mem(), and record_last_mem_set_info().

◆ occr_obstack

struct obstack occr_obstack
static

◆ reg_avail_info

int* reg_avail_info
static
Array where each element is the CUID if the insn that last set the hard
register with the number of the element, since the start of the current
basic block.

This array is used during the building of the hash table (step 1) to
determine if a reg is killed before the end of a basic block.

It is also used when eliminating partial redundancies (step 2) to see
if a reg was modified since the start of a basic block.   

◆ stats

struct [struct].stats stats

◆ transp

sbitmap* transp
static
Vector of simple bitmaps indexed by block number.  Each component sbitmap
indicates which expressions are transparent through the block.   

Referenced by compute_expr_transp(), gcse_after_reload_main(), and get_bb_avail_insn().

◆ uid_cuid

int* uid_cuid
static
Mapping of insn UIDs to CUIDs.
CUIDs are like UIDs except they increase monotonically in each basic
block, have no gaps, and only apply to real insns.   

Referenced by alloc_mem(), and free_mem().

◆ unoccr_obstack

struct obstack unoccr_obstack
static