GCC Middle and Back End API Reference
|
Data Structures | |
struct | coalesce_pair |
struct | coalesce_pair_hasher |
struct | cost_one_pair_d |
struct | coalesce_list_d |
struct | ssa_conflicts_d |
struct | live_track_d |
struct | ssa_name_var_hash |
Typedefs | |
typedef struct coalesce_pair * | coalesce_pair_p |
typedef struct coalesce_pair * | const_coalesce_pair_p |
typedef hash_table < coalesce_pair_hasher > | coalesce_table_type |
typedef coalesce_table_type::iterator | coalesce_iterator_type |
typedef struct cost_one_pair_d * | cost_one_pair_p |
typedef struct coalesce_list_d * | coalesce_list_p |
typedef struct ssa_conflicts_d * | ssa_conflicts_p |
typedef struct live_track_d * | live_track_p |
typedef coalesce_table_type::iterator coalesce_iterator_type |
typedef struct coalesce_list_d * coalesce_list_p |
This structure maintains the list of coalesce pairs.
typedef struct coalesce_pair * coalesce_pair_p |
@verbatim
Coalesce SSA_NAMES together for the out-of-ssa pass. Copyright (C) 2004-2013 Free Software Foundation, Inc. Contributed by Andrew MacLeod amacl eod@ redha t.co m
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/.
This set of routines implements a coalesce_list. This is an object which is used to track pairs of ssa_names which are desirable to coalesce together to avoid copies. Costs are associated with each pair, and when all desired information has been collected, the object can be used to order the pairs for processing.
This structure defines a pair entry.
typedef struct coalesce_pair* const_coalesce_pair_p |
typedef struct cost_one_pair_d * cost_one_pair_p |
typedef struct live_track_d * live_track_p |
This structure is used to efficiently record the current status of live SSA_NAMES when building a conflict graph. LIVE_BASE_VAR has a bit set for each base variable which has at least one ssa version live. LIVE_BASE_PARTITIONS is an array of bitmaps using the basevar table as an index, and is used to track what partitions of each base variable are live. This makes it easy to add conflicts between just live partitions with the same base variable. The values in LIVE_BASE_PARTITIONS are only valid if the base variable is marked as being live. This delays clearing of these bitmaps until they are actually needed again.
typedef struct ssa_conflicts_d * ssa_conflicts_p |
This represents a conflict graph. Implemented as an array of bitmaps. A full matrix is used for conflicts rather than just upper triangular form. this make sit much simpler and faster to perform conflict merges.
|
inlinestatic |
Add a coalesce between P1 and P2 in list CL with a cost of VALUE.
Once the value is at least MUST_COALESCE_COST - 1, leave it that way.
References coalesce_pair::cost.
Referenced by coalesce_partitions(), create_outofssa_var_map(), and print_exprs().
|
inlinestatic |
Referenced by print_exprs().
|
inlinestatic |
Attempt to coalesce ssa versions X and Y together using the partition mapping in MAP and checking conflicts in GRAPH. Output any debug info to DEBUG, if it is nun-NULL.
z is the new combined partition. Remove the other partition from the list, and merge the conflicts.
References edge_def::dest_idx, fail_abnormal_edge_coalesce(), edge_def::flags, gsi_end_p(), gsi_next(), gsi_start_phis(), gsi_stmt(), and basic_block_def::preds.
|
static |
Build a conflict graph based on LIVEINFO. Any partitions which are in the partition view of the var_map liveinfo is based on get entries in the conflict graph. Only conflicts between ssa_name partitions with the same base variable are added.
Start with live on exit temporaries.
A copy between 2 partitions does not introduce an interference by itself. If they did, you would never be able to coalesce two things which are copied. If the two variables really do conflict, they will conflict elsewhere in the program. This is handled by simply removing the SRC of the copy from the live list, and processing the stmt normally.
If result of a PHI is unused, looping over the statements will not record any conflicts since the def was never live. Since the PHI node is going to be translated out of SSA form, it will insert a copy. There must be a conflict recorded between the result of the PHI and any variables that are live. Otherwise the out-of-ssa translation may create incorrect code.
|
inlinestatic |
Return cost of execution of copy instruction with FREQUENCY.
Base costs on BB frequencies bounded by 1.
Referenced by create_outofssa_var_map().
|
inlinestatic |
Return the cost of executing a copy instruction in basic block BB.
References edge_def::flags, and mult.
Referenced by create_outofssa_var_map().
|
inlinestatic |
Return the cost of executing a copy instruction on edge E.
Inserting copy on critical edge costs more than inserting it elsewhere.
Putting code on EH edge that leads to BB with multiple predecestors imply splitting of edge too.
If there are multiple EH predecestors, we also copy EH regions and produce separate landing pad. This is expensive.
References edge_def::flags.
Referenced by print_exprs().
|
static |
Attempt to Coalesce partitions in MAP which occur in the list CL using GRAPH. Debug output is sent to DEBUG if it is non-NULL.
First, coalesce all the copies across abnormal edges. These are not placed in the coalesce list because they do not need to be sorted, and simply consume extra memory/compilation time in large programs.
Now process the items in the coalesce list.
Assert the coalesces have the same base variable.
References add_coalesce(), bitmap_set_bit(), calculate_live_ranges(), hash_table< Descriptor, Allocator >::create(), create_coalesce_list(), create_outofssa_var_map(), delete_coalesce_list(), hash_table< Descriptor, Allocator >::dispose(), dump_file, dump_flags, dump_var_map(), hash_table< Descriptor, Allocator >::find_slot(), graph, has_zero_uses(), map, num_var_partitions(), and partition_view_bitmap().
var_map coalesce_ssa_name | ( | void | ) |
Reduce the number of copies by coalescing variables in the function. Return a partition map with the resulting coalesces.
We need to coalesce all names originating same SSA_NAME_VAR so debug info remains undisturbed.
Don't calculate live ranges for variables not in the coalesce list.
Build a conflict graph.
First, coalesce all live on entry variables to their base variable. This will ensure the first use is coming from the correct location.
Now coalesce everything in the list.
|
static |
Comparison function to allow qsort to sort P1 and P2 in Ascending order.
Since qsort does not guarantee stability we use the elements as a secondary key. This provides us with independence from the host's implementation of the sorting algorithm.
References hash_table< Descriptor, Allocator >::elements(), and coalesce_list_d::list.
|
inlinestatic |
Create a new empty coalesce list object and return it.
References coalesce_list_d::cost_one_list, hash_table< Descriptor, Allocator >::dispose(), free(), coalesce_list_d::list, coalesce_list_d::num_sorted, and coalesce_list_d::sorted.
Referenced by coalesce_partitions().
|
static |
This function creates a var_map for the current function as well as creating a coalesce list for use later in the out of ssa process.
Register ssa_names and coalesces between the args and the result of all PHI.
Register USE and DEF operands in each statement.
Check for copy coalesces.
Now process result decls and live on entry variables for entry into the coalesce list.
Add coalesces between all the result decls.
Mark any default_def variables as being in the coalesce list since they will have to be coalesced with the base variable. If not marked as present, they won't be in the coalesce view.
References add_coalesce(), bitmap_set_bit(), coalesce_cost(), coalesce_cost_bb(), gimple_asm_input_op(), gimple_asm_ninputs(), gimple_asm_noutputs(), gimple_asm_output_op(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_ssa_name_copy_p(), gimple_can_coalesce_p(), and optimize_bb_for_size_p().
Referenced by coalesce_partitions().
|
inlinestatic |
Delete coalesce list CL.
Referenced by coalesce_partitions().
|
static |
This routine will free the memory associated with PTR.
|
static |
Send debug info for coalesce list CL to file F.
|
inlinestatic |
Print a failure to coalesce a MUST_COALESCE pair X and Y.
Referenced by attempt_coalesce().
|
static |
Find a matching coalesce pair object in CL for the pair P1 and P2. If one isn't found, return NULL if CREATE is false, otherwise create a new coalesce pair object and return it.
Normalize so that p1 is the smaller value.
References coalesce_pair::cost, coalesce_pair::first_element, coalesce_pair::second_element, and coalesce_list_d::sorted.
|
inlinestatic |
This function will adds PARTITION to the live list in PTR.
If this base var wasn't live before, it is now. Clear the element list since it was delayed until needed.
Referenced by live_track_live_p().
|
inlinestatic |
This routine will clear all live partitions in PTR.
Simply clear the live base list. Anything marked as live in the element lists will be cleared later if/when the base variable ever comes alive again.
References gsi_stmt(), live_track_live_p(), and live_track_process_def().
|
inlinestatic |
Clear the live bit for VAR in PTR.
Referenced by live_track_init().
|
inlinestatic |
Initialize PTR with the partitions set in INIT.
Mark all live on exit partitions.
References gimple_assign_copy_p(), gimple_assign_lhs(), gimple_assign_rhs1(), and live_track_clear_var().
|
inlinestatic |
Return TRUE if VAR is live in PTR.
References live_track_add_partition().
Referenced by live_track_clear_base_vars().
|
inlinestatic |
This routine will process a DEF in PTR. DEF will be removed from the live lists, and if there are any other live partitions with the same base variable, conflicts will be added to GRAPH.
Clear the liveness bit.
If the bitmap isn't empty now, conflicts need to be added.
Referenced by live_track_clear_base_vars().
|
inlinestatic |
This routine will add USE to PTR. USE will be marked as live in both the ssa live map and the live bitmap for the root of USE.
Mark as live in the appropriate live list.
References bitmap_clear(), and live_track_d::live_base_var.
|
inlinestatic |
This function will remove PARTITION from the live list in PTR.
If the element list is empty, make the base variable not live either.
References basevar_index(), bitmap_bit_p(), live_track_d::live_base_partitions, live_track_d::live_base_var, and live_track_d::map.
|
static |
This routine will create a new live track structure based on the partitions in MAP.
Make sure there is a partition view in place.
References basevar_index(), bitmap_clear(), bitmap_set_bit(), live_track_d::live_base_partitions, live_track_d::live_base_var, and live_track_d::map.
|
inlinestatic |
Return the number of unique coalesce pairs in CL.
|
inlinestatic |
Retrieve the most expensive remaining pair to coalesce from CL. Returns the 2 elements via P1 and P2. Their calculated cost is returned by the function. NO_BEST_COALESCE is returned if the coalesce list is empty.
|
inlinestatic |
Retrieve a pair to coalesce from the cost_one_list in CL. Returns the 2 elements via P1 and P2. 1 is returned by the function if there is a pair, NO_BEST_COALESCE is returned if there aren't any.
|
inlinestatic |
Shortcut routine to print messages to file F of the form: "STR1 EXPR1 STR2 EXPR2 STR3."
References add_coalesce(), add_cost_one_coalesce(), bitmap_set_bit(), coalesce_cost_edge(), edge_def::flags, and has_single_use().
|
static |
Prepare CL for removal of preferred pairs. When finished they are sorted in order from most important coalesce to least important.
Allocate a vector for the pair pointers.
Populate the vector with pointers to the pairs.
Already sorted.
If there are only 2, just pick swap them if the order isn't correct.
Only call qsort if there are more than 2 items.
References coalesce_pair::cost, and coalesce_list_d::sorted.
|
inlinestatic |
Add conflicts between X and Y in graph PTR.
|
inlinestatic |
Add a conflict with Y to the bitmap for X in graph PTR.
If there are no conflicts yet, allocate the bitmap and set bit.
References bitmap_set_bit(), and ssa_conflicts_d::conflicts.
|
inlinestatic |
Free storage for conflict graph PTR.
|
static |
Dump a conflicts graph.
|
inlinestatic |
Merge all Y's conflict into X in graph PTR.
Add a conflict between X and every one Y has. If the bitmap doesn't exist, then it has already been coalesced, and we don't need to add a conflict.
If X has conflicts, add Y's to X.
If X has no conflicts, simply use Y's.
|
inlinestatic |
Return an empty new conflict graph for SIZE elements.
|
inlinestatic |
Test if elements X and Y conflict in graph PTR.
Avoid the lookup if Y has no conflicts.
References ssa_conflicts_d::conflicts.