GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "diagnostic-core.h"
#include "toplev.h"
#include "rtl.h"
#include "tree.h"
#include "tm_p.h"
#include "regs.h"
#include "hard-reg-set.h"
#include "flags.h"
#include "insn-config.h"
#include "recog.h"
#include "basic-block.h"
#include "function.h"
#include "expr.h"
#include "except.h"
#include "params.h"
#include "cselib.h"
#include "intl.h"
#include "obstack.h"
#include "tree-pass.h"
#include "hashtab.h"
#include "df.h"
#include "dbgcnt.h"
#include "target.h"
#include "cfgloop.h"
Data Structures | |
struct | occr |
struct | expr |
struct | hash_table_d |
Macros | |
#define | GOBNEW(T) ((T *) cprop_alloc (sizeof (T))) |
#define | GOBNEWVAR(T, S) ((T *) cprop_alloc ((S))) |
#define | MAX_USES 8 |
Typedefs | |
typedef struct occr * | occr_t |
Variables | |
static struct obstack | cprop_obstack |
static struct hash_table_d | set_hash_table |
static rtx * | implicit_sets |
static int * | implicit_set_indexes |
static regset | reg_set_bitmap |
static int | bytes_used |
static int | local_const_prop_count |
static int | local_copy_prop_count |
static int | global_const_prop_count |
static int | global_copy_prop_count |
static sbitmap * | cprop_avloc |
static sbitmap * | cprop_kill |
static sbitmap * | cprop_avin |
static sbitmap * | cprop_avout |
static rtx | reg_use_table [MAX_USES] |
static unsigned | reg_use_count |
static int | bypass_last_basic_block |
#define GOBNEW | ( | T | ) | ((T *) cprop_alloc (sizeof (T))) |
Referenced by hash_expr(), and load_killed_in_block_p().
#define GOBNEWVAR | ( | T, | |
S | |||
) | ((T *) cprop_alloc ((S))) |
#define MAX_USES 8 |
Copy/constant propagation. Maximum number of register uses in an insn that we handle.
Referenced by compute_local_properties().
|
static |
Allocate vars used for copy/const propagation. N_BLOCKS is the number of basic blocks. N_SETS is the number of sets.
References bitmap_set_bit, BLOCK_FOR_INSN, and occr::insn.
|
static |
Allocate space for the set/expr hash TABLE. It is used to determine the number of buckets to use.
Attempt to maintain efficient use of hash table. Making it an odd number is simplest for now. ??? Later take some measurements.
|
static |
Subroutine of bypass_conditional_jumps that attempts to bypass the given basic block BB which has more than one predecessor. If not NULL, SETCC is the first instruction of BB, which is immediately followed by JUMP_INSN JUMP. Otherwise, SETCC is NULL, and JUMP is the first insn of BB. Returns nonzero if a change was made.
During the jump bypassing pass, we may place copies of SETCC instructions on CFG edges. The following routine must be careful to pay attention to these inserted insns when performing its transformations.
Determine set of register uses in INSN.
If we are to preserve loop structure then do not bypass a loop header. This will either rotate the loop, create multiple entry loops or even irreducible regions.
We can't redirect edges from new basic blocks.
The irreducible loops created by redirecting of edges entering the loop from outside would decrease effectiveness of some of the following optimizations, so prevent this.
Check the data flow is valid after edge insertions.
Jump bypassing may have already placed instructions on edges of the CFG. We can't bypass an outgoing edge that has instructions associated with it, as these insns won't get executed if the incoming edge is redirected.
Don't bypass edges containing instructions.
Avoid unification of the edge with other edges from original branch. We would end up emitting the instruction on "both" edges.
Copy the register setter to the redirected edge. Don't copy CC0 setters, as CC0 is dead after jump.
|
static |
Find basic blocks with more than one predecessor that only contain a single conditional jump. If the result of the comparison is known at compile-time from any incoming edge, redirect that edge to the appropriate target. Return nonzero if a change was made.
This function is now mis-named, because we also handle indirect jumps.
Note we start at block 1.
Check for more than one predecessor.
If we bypassed any register setting insns, we inserted a copy on the redirected edge. These need to be committed.
|
static |
Hash table support. Top level routine to do the dataflow analysis needed by copy/const propagation.
Merge implicit sets into CPROP_AVIN. They are always available at the entry of their basic block. We need to do this because 1) implicit sets aren't recorded for the local pass so they cannot be propagated within their basic block by this pass and 2) the global pass would otherwise propagate them only in the successors of their basic block.
|
static |
Compute the hash TABLE for doing copy/const propagation or expression hash table.
Initialize count of number of entries in hash table.
References REGNO, and REGNO_REG_SET_P.
|
static |
Top level function to create an assignment hash table.
Assignment entries are placed in the hash table if
Currently src must be a pseudo-reg or a const_int.
TABLE is the table computed.
Allocate vars to track sets of regs.
Reset tables used to keep track of what's not yet invalid [since the end of the block].
Go over all insns from the last to the first. This is convenient for tracking available registers, i.e. not set between INSN and the end of the basic block BB.
Only real insns are interesting.
Record interesting sets from INSN in the hash table.
Any registers set in INSN will make SETs above it not AVAIL.
Insert implicit sets in the hash table, pretending they appear as insns at the head of the basic block.
References get_max_insn_count(), hash_table_d::size, and hash_table_d::table.
|
static |
Compute the local properties of each recorded expression.
Local properties are those that are defined by the block, irrespective of other blocks.
An expression is killed in a block if its operands, either DEST or SRC, are modified in the block.
An expression is computed (locally available) in a block if it is computed at least once and expression would contain the same value if the computation was moved to the end of the block.
KILL and COMP are destination sbitmaps for recording local properties.
Initialize the bitmaps that were passed in.
For each definition of the destination pseudo-reg, the expression is killed in the block where the definition is.
If the source is a pseudo-reg, for each definition of the source, the expression is killed in the block where the definition is.
The occurrences recorded in avail_occr are exactly those that are locally available in the block where they are.
References GET_CODE, GET_RTX_FORMAT, GET_RTX_LENGTH, MAX_USES, REG_P, reg_use_count, and XEXP.
Referenced by free_cprop_mem().
|
static |
Subroutine of cprop_insn that tries to propagate constants. FROM is what we will try to replace, SRC is the constant we will try to substitute for it and INSN is the instruction where this will be happening.
Check for reg or cc0 setting instructions followed by conditional branch instructions first.
Handle normal insns next.
Try to propagate a CONST_INT into a conditional jump. We're pretty specific about what we will handle in this code, we can extend this as necessary over time. Right now the insn in question must look like (set (pc) (if_then_else ...))
|
static |
Cover function to obstack_alloc.
|
static |
Determine whether the rtx X should be treated as a constant for CPROP. Since X might be inserted more than once we have to take care that it is sharable.
Referenced by implicit_set_cond_p(), and try_replace_reg().
|
static |
Perform constant and copy propagation on INSN. Return nonzero if a change was made.
We may win even when propagating constants into notes.
If the register has already been set in this block, there's nothing we can do.
Find an assignment that sets reg_used and is available at the start of the block.
Constant propagation.
The original insn setting reg_used may or may not now be deletable. We leave the deletion to DCE.
FIXME: If it turns out that the insn isn't deletable, then we may have unnecessarily extended register lifetimes and made things worse.
If try_replace_reg simplified the insn, the regs found by find_used_regs may not be valid anymore. Start over.
|
static |
Subroutine of cprop_insn that tries to propagate constants into JUMP_INSNS. JUMP must be a conditional jump. If SETCC is non-NULL it is the instruction that immediately precedes JUMP, and must be a single SET of a register. FROM is what we will try to replace, SRC is the constant we will try to substitute for it. Return nonzero if a change was made.
Prefer REG_EQUAL notes except those containing EXPR_LISTs.
First substitute the SETCC condition into the JUMP instruction, then substitute that given values into this expanded JUMP.
If no simplification can be made, then try the next register.
If this is now a no-op delete it, otherwise this must be a valid insn.
Ensure the value computed inside the jump insn to be equivalent to one computed by setcc.
When (some) constants are not valid in a comparison, and there are two registers to be replaced by constants before the entire comparison can be folded into a constant, we need to keep intermediate information in REG_EQUAL notes. For targets with separate compare insns, such notes are added by try_replace_reg. When we have a combined compare-and-branch instruction, however, we need to attach a note to the branch itself to make this optimization work.
Remove REG_EQUAL note after simplification.
If a conditional jump has been changed into unconditional jump, remove the jump and make the edge fallthru - this is always called in cfglayout mode.
|
static |
Try to perform local const/copy propagation on X in INSN.
Rule out USE instructions and ASM statements as we don't want to change the hard registers mentioned.
Don't copy propagate if it has attached REG_EQUIV note. At this point this only function parameters should have REG_EQUIV notes and if the argument slot is used somewhere explicitly, it means address of parameter has been taken, so we should not extend the lifetime of the pseudo.
|
static |
Dump the hash table TABLE to file FILE under the name NAME.
Flattened out table, so it's printed in proper order.
References DF_INSN_INFO_DEFS, DF_INSN_INFO_GET, DF_REF_REGNO, and SET_REGNO_REG_SET.
|
static |
Referenced by one_cprop_pass().
|
staticread |
Find a set of REGNOs that are available on entry to INSN's block. Return NULL no such set is found.
SET1 contains the last set found that can be returned to the caller for use in a substitution.
Loops are not possible here. To get a loop we would need two sets available at the start of the block containing INSN. i.e. we would need two sets like this available at the start of the block: (set (reg X) (reg Y)) (set (reg Y) (reg X)) This can not happen since the set of (reg Y) would have killed the set of (reg X) making it unavailable at the start of this block.
Find a set that is available at the start of the block which contains INSN.
If no available set was found we've reached the end of the (possibly empty) copy chain.
We know the set is available. Now check that SRC is locally anticipatable (i.e. none of the source operands have changed since the start of the block). If the source operand changed, we may still use it for the next iteration of this loop, but we may not use it for substitutions.
If the source of the set is anything except a register, then we have reached the end of the copy chain.
Follow the copy chain, i.e. start another iteration of the loop and see if we have an available copy into SRC.
SET1 holds the last set that was available and anticipatable at INSN.
|
staticread |
Find a set of REGNO to a constant that is available at the end of basic block BB. Return NULL if no such set is found. Based heavily upon find_avail_set.
Referenced by find_implicit_sets().
|
static |
Find the implicit sets of a function. An "implicit set" is a constraint on the value of a variable, implied by a conditional jump. For example, following "if (x == 2)", the then branch may be optimized as though the conditional performed an "explicit set", in this example, "x = 2". This function records the set patterns that are implicit at the start of each basic block.
If an implicit set is found but the set is implicit on a critical edge, this critical edge is split.
Return true if the CFG was modified, false otherwise.
Check for more than one successor.
If no condition is found or if it isn't of a suitable form, ignore it.
If DEST doesn't go anywhere, ignore it.
We have found a suitable implicit set. Try to record it now as a SET in DEST. If DEST has more than one predecessor, the edge between BB and DEST is a critical edge and we must split it, because we can only record one implicit set per DEST basic block.
Confess our sins.
References current_loops, expr::dest, EDGE_COMPLEX, ei_next(), ei_safe_edge(), ei_start, find_bypass_set(), find_reg_equal_equiv_note(), find_used_regs(), edge_def::flags, FOR_EACH_EDGE, loop::header, basic_block_def::index, edge_def::insns, basic_block_def::loop_father, note_uses(), NULL, PATTERN, basic_block_def::preds, edge_def::edge_def_insns::r, reg_killed_on_edge(), reg_use_count, REGNO, edge_def::src, expr::src, and XEXP.
|
static |
Set up a list of register numbers used in INSN. The found uses are stored in `reg_use_table'. `reg_use_count' is initialized to zero before entry, and contains the number of uses in the table upon exit.
??? If a register appears multiple times we will record it multiple times. This doesn't hurt anything but it will slow things down.
repeat is used to turn tail-recursion into iteration since GCC can't do it when there's no return value.
Recursively scan the operands of this expression.
If we are about to do the last recursive call needed at this level, change it into iteration. This function is called enough to be worth it.
Referenced by find_implicit_sets().
rtx fis_get_condition | ( | ) |
Similar to get_condition, only the resulting condition must be valid at JUMP, instead of at EARLIEST.
This differs from noce_get_condition in ifcvt.c in that we prefer not to settle for the condition variable in the jump instruction being integral. We prefer to be able to record the value of a user variable, rather than the value of a temporary used in a condition. This could be solved by recording the value of every register scanned by canonicalize_condition, but this would require some code reorganization.
|
static |
Free vars used by copy/const propagation.
References bitmap_set_bit, compute_available(), compute_local_properties(), FOR_EACH_BB, implicit_set_indexes, basic_block_def::index, and set_hash_table.
|
static |
Free things allocated by alloc_hash_table.
|
static |
All the passes implemented in this file. Each pass has its own gate and execute function, and at the end of the file a pass definition for passes.c.
We do not construct an accurate cfg in functions which call setjmp, so none of these passes runs if the function calls setjmp. FIXME: Should just handle setjmp via REG_SETJMP notes.
Referenced by one_cprop_pass().
|
static |
Process INSN and add hash table entries as appropriate.
Pick out the sets of INSN and for other forms of instructions record what's been modified.
|
static |
Scan SET present in INSN and add an entry to the hash TABLE. IMPLICIT is true if it's an implicit set, false otherwise.
See if a REG_EQUAL note shows this equivalent to a simpler expression.
This allows us to do a single CPROP pass and still eliminate redundant constants, addresses or other expressions that are constructed with multiple instructions.
However, keep the original SRC if INSN is a simple reg-reg move. In In this case, there will almost always be a REG_EQUAL note on the insn that sets SRC. By recording the REG_EQUAL value here as SRC for INSN, we miss copy propagation opportunities.
Note that this does not impede profitable constant propagations. We "look through" reg-reg sets in lookup_set.
Record sets for constant/copy propagation.
Referenced by hash_scan_set().
|
static |
Hash a set of register REGNO.
Sets are hashed on the register that is set. This simplifies the PRE copy propagation code.
??? May need to make things more elaborate. Later, as necessary.
Referenced by reg_available_p().
|
static |
Check the comparison COND to see if we can safely form an implicit set from it.
COND must be either an EQ or NE comparison.
The first operand of COND must be a pseudo-reg.
The second operand of COND must be a suitable constant.
We can't perform this optimization if either operand might be or might contain a signed zero.
It is sufficient to check if CST is or contains a zero. We must handle float, complex, and vector. If any subpart is a zero, then the optimization can't be performed.
??? The complex and vector checks are not implemented yet. We just always return zero for them.
References bitmap_bit_p, cprop_constant_p(), lookup_set(), next_set(), REG_P, REGNO, set_hash_table, and expr::src.
|
static |
Insert assignment DEST:=SET from INSN in the hash table. DEST is a register and SET is a register or a suitable constant. If the assignment is already present in the table, record it as the last occurrence in INSN's basic block. IMPLICIT is true if it's an implicit set, false otherwise.
This is the first pattern that hashed to this index.
Add EXPR to end of this hash chain.
Set the fields of the expr element. We must copy X because it can be modified when copy propagation is performed on its operands.
Now record the occurrence.
Found another instance of the expression in the same basic block. Prefer this occurrence to the currently recorded one. We want the last one in the block and the block is scanned from start to end.
First occurrence of this expression in this basic block.
Record bitmap_index of the implicit set in implicit_set_indexes.
|
static |
Return true if the graph is too expensive to optimize. PASS is the optimization about to be performed.
Trying to perform global optimizations on flow graphs which have a high connectivity will take a long time and is unlikely to be particularly useful.
In normal circumstances a cfg should have about twice as many edges as blocks. But we do not want to punish small functions which have a couple switch statements. Rather than simply threshold the number of blocks, uses something with a more graceful degradation.
If allocating memory for the cprop bitmap would take up too much storage it's better just to disable the optimization.
|
static |
Like find_used_regs, but avoid recording uses that appear in input-output contexts such as zero_extract or pre_dec. This restricts the cases we consider to those for which local cprop can legitimately make replacements.
Can only legitimately appear this early in the context of stack pushes for function arguments, but handle all of the codes nonetheless.
Setting a subreg of a register larger than word_mode leaves the non-written words unchanged.
|
static |
Do local const/copy propagation (i.e. within each basic block).
Forget everything at the end of a basic block.
|
staticread |
Expression tracking support. Lookup REGNO in the set TABLE. The result is a pointer to the table entry, or NULL if not found.
References sbitmap_vector_alloc().
Referenced by implicit_set_cond_p(), and try_replace_reg().
rtl_opt_pass* make_pass_rtl_cprop | ( | ) |
|
static |
Record as unavailable all registers that are DEF operands of INSN.
|
static |
Record things set by INSN. This data is used by reg_not_set_p.
|
staticread |
Return the next entry for REGNO in list EXPR.
Referenced by implicit_set_cond_p(), and try_replace_reg().
|
static |
Main function for the CPROP pass.
Return if there's nothing to do, or it is too expensive.
Do a local const/copy propagation pass first. The global pass only handles global opportunities. If the local pass changes something, remove any unreachable blocks because the CPROP global dataflow analysis may get into infinite loops for CFGs with unreachable blocks. FIXME: This local pass should not be necessary after CSE (but for some reason it still is). It is also (proven) not necessary to run the local pass right after FWPWOP. FIXME: The global analysis would not get into infinite loops if it would use the DF solver (via df_simple_dataflow) instead of the solver implemented in this file.
Determine implicit sets. This may change the CFG (split critical edges if that exposes an implicit set). Note that find_implicit_sets() does not rely on up-to-date DF caches so that we do not have to re-run df_analyze() even if local CPROP changed something. ??? This could run earlier so that any uncovered implicit sets sets could be exploited in local_cprop_pass() also. Later.
If local_cprop_pass() or find_implicit_sets() changed something, run df_analyze() to bring all insn caches up-to-date, and to take new basic blocks from edge splitting on the DF radar. NB: This also runs the fast DCE pass, because execute_rtl_cprop sets DF_LR_RUN_DCE.
Initialize implicit_set_indexes array.
Free implicit_sets before peak usage.
Allocate vars to track sets of regs.
Reset tables used to keep track of what's still valid [since the start of the block].
Keep track of everything modified by this insn.
??? Need to be careful w.r.t. mods done to INSN. Don't call mark_oprs_set if we turned the insn into a NOTE, or deleted the insn.
References execute(), execute_rtl_cprop(), and gate_rtl_cprop().
|
static |
Return nonzero if register X is unchanged from INSN to the end of INSN's basic block.
References expr::dest, hash_set(), expr::next_same_hash, NULL, REGNO, hash_table_d::size, expr::src, and hash_table_d::table.
|
static |
Subroutine of bypass_block that checks whether a pseudo is killed by any of the instructions inserted on an edge. Jump bypassing places condition code setters on CFG edges using insert_insn_on_edge. This function is required to check that our data flow analysis is still valid prior to commit_edge_insertions.
References copy_insn(), insert_insn_on_edge(), PATTERN, and SET_DEST.
Referenced by find_implicit_sets().
|
static |
Return nonzero if the register X has not been set yet [since the start of the basic block containing INSN].
Referenced by try_replace_reg().
|
static |
Reset tables used to keep track of what's still available [since the start of the block].
Maintain a bitmap of which regs have been set since beginning of the block.
|
static |
Try to replace all uses of FROM in INSN with TO. Return nonzero if successful.
Usually we substitute easy stuff, so we won't copy everything. We however need to take care to not duplicate non-trivial CONST expressions.
Try to simplify SET_SRC if we have substituted a constant.
If there is already a REG_EQUAL note, update the expression in it with our replacement.
If above failed and this is a single set, try to simplify the source of the set given our substitution. We could perhaps try this for multiple SETs, but it probably won't buy us anything.
If we've failed perform the replacement, have a single SET to a REG destination and don't yet have a note, add a REG_EQUAL note to not lose information.
Registers can also appear as uses in SET_DEST if it is a MEM. We could perhaps try this for multiple SETs, but it probably won't buy us anything.
REG_EQUAL may get simplified into register. We don't allow that. Remove that note. This code ought not to happen, because previous code ought to synthesize reg-reg move, but be on the safe side.
References bitmap_bit_p, BLOCK_FOR_INSN, cprop_constant_p(), lookup_set(), next_set(), reg_not_set_p(), REG_P, REGNO, set_hash_table, and expr::src.
|
static |
Bypass conditional jumps. The value of last_basic_block at the beginning of the jump_bypass pass. The use of redirect_edge_and_branch_force may introduce new basic blocks, but the data flow analysis is only valid for basic block indices less than bypass_last_basic_block.
|
static |
Various variables for statistics gathering. Memory used in a pass. This isn't intended to be absolutely precise. Its intent is only to keep an eye on memory usage.
|
static |
Global properties of assignments (computed from the local properties).
|
static |
Compute copy/constant propagation working variables. Local properties of assignments.
|
static |
|
static |
|
static |
Global constant/copy propagation for RTL. Copyright (C) 1997-2013 Free Software Foundation, Inc.
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/. An obstack for our working variables.
|
static |
Number of global constants propagated.
|
static |
Number of global copies propagated.
|
static |
Array of indexes of expressions for implicit set patterns indexed by basic block index. In other words, implicit_set_indexes[i] is the bitmap_index of the expression whose RTX is implicit_sets[i].
Referenced by free_cprop_mem().
|
static |
Array of implicit set patterns indexed by basic block index.
|
static |
Number of local constants propagated.
|
static |
Number of local copies propagated.
|
static |
Bitmap containing one bit for each register in the program. Used when performing GCSE to track which registers have been set since the start or end of the basic block while traversing that block.
|
static |
Index into `reg_use_table' while building it.
Referenced by compute_local_properties(), and find_implicit_sets().
Table of uses (registers, both hard and pseudo) found in an insn. Allocated statically to avoid alloc/free complexity and overhead.
|
static |
Copy propagation hash table.
Referenced by free_cprop_mem(), implicit_set_cond_p(), and try_replace_reg().