aboutsummaryrefslogtreecommitdiff
path: root/gcc/ipa-reference.c
diff options
context:
space:
mode:
authorLawrence Crowl <crowl@google.com>2012-10-31 23:15:10 +0000
committerLawrence Crowl <crowl@gcc.gnu.org>2012-10-31 23:15:10 +0000
commit5d59b5e18a878c2201471e529c40f15d49905fc8 (patch)
tree7209857044c64b9be2543946aeb701d483464efa /gcc/ipa-reference.c
parent2a381a57f3061e171923a14083ac37d957c9c98d (diff)
downloadgcc-5d59b5e18a878c2201471e529c40f15d49905fc8.zip
gcc-5d59b5e18a878c2201471e529c40f15d49905fc8.tar.gz
gcc-5d59b5e18a878c2201471e529c40f15d49905fc8.tar.bz2
This patch implements generic type query and conversion functions,
and applies them to the use of cgraph_node, varpool_node, and symtab_node. The functions are: bool is_a <TYPE> (pointer) Tests whether the pointer actually points to a more derived TYPE. TYPE *as_a <TYPE> (pointer) Converts pointer to a TYPE*. TYPE *dyn_cast <TYPE> (pointer) Converts pointer to TYPE* if and only if "is_a <TYPE> pointer". Otherwise, returns NULL. This function is essentially a checked down cast. These functions reduce compile time and increase type safety when treating a generic item as a more specific item. In essence, the code change is from if (symtab_function_p (node)) { struct cgraph_node *cnode = cgraph (node); .... } to if (cgraph_node *cnode = dyn_cast <cgraph_node> (node)) { .... } The necessary conditional test defines a variable that holds a known good pointer to the specific item and avoids subsequent conversion calls and the assertion checks that may come with them. When, the property test is embedded within a larger condition, the variable declaration gets pulled out of the condition. (This leaves some room for using the variable inappropriately.) if (symtab_variable_p (node) && varpool (node)->finalized) varpool_analyze_node (varpool (node)); becomes varpool_node *vnode = dyn_cast <varpool_node> (node); if (vnode && vnode->finalized) varpool_analyze_node (vnode); Note that we have converted two sets of assertions in the calls to varpool into safe and efficient use of a variable. There are remaining calls to symtab_function_p and symtab_variable_p that do not involve a pointer to a more specific type. These have been converted to calls to a functions is_a <cgraph_node> and is_a <varpool_node>. The original predicate functions have been removed. The cgraph.h header defined both a struct and a function with the name varpool_node. This name overloading can cause some unintuitive error messages when, as is common in C++, one omits the struct keyword when using the type. I have renamed the function to varpool_node_for_decl. Tested on x86_64. Index: gcc/ChangeLog 2012-10-31 Lawrence Crowl <crowl@google.com> * is-a.h: New. (is_a <T> (U*)): New. Test for is-a relationship. (as_a <T> (U*)): New. Treat as a derived type. (dyn_cast <T> (U*)): New. Conditionally cast based on is_a. * cgraph.h (varpool_node): Rename to varpool_node_for_decl. Adjust callers to match. (is_a_helper <cgraph_node>::test (symtab_node_def *)): New. (is_a_helper <varpool_node>::test (symtab_node_def *)): New. (symtab_node_def::try_function): New. Change most calls to symtab_function_p with calls to dyn_cast <cgraph_node> (p). (symtab_node_def::try_variable): New. Change most calls to symtab_variable_p with calls to dyn_cast <varpool_node> (p). (symtab_function_p): Remove. Change callers to use is_a <cgraph_node> (p) instead. (symtab_variable_p): Remove. Change callers to use is_a <varpool_node> (p) instead. * cgraph.c (cgraph_node_for_asm): Remove redundant call to symtab_node_for_asm. * cgraphunit.c (symbol_finalized_and_needed): New. (symbol_finalized): New. (cgraph_analyze_functions): Split complicated conditionals out into above new functions. * Makefile.in (CGRAPH_H): Add is-a.h as used by cgraph.h. From-SVN: r193051
Diffstat (limited to 'gcc/ipa-reference.c')
-rw-r--r--gcc/ipa-reference.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/gcc/ipa-reference.c b/gcc/ipa-reference.c
index 9072fe8..a17d75b 100644
--- a/gcc/ipa-reference.c
+++ b/gcc/ipa-reference.c
@@ -482,7 +482,7 @@ analyze_function (struct cgraph_node *fn)
local = init_function_info (fn);
for (i = 0; ipa_ref_list_reference_iterate (&fn->symbol.ref_list, i, ref); i++)
{
- if (!symtab_variable_p (ref->referred))
+ if (!is_a <varpool_node> (ref->referred))
continue;
var = ipa_ref_varpool_node (ref)->symbol.decl;
if (!is_proper_for_analysis (var))
@@ -979,8 +979,6 @@ stream_out_bitmap (struct lto_simple_output_block *ob,
static void
ipa_reference_write_optimization_summary (void)
{
- struct cgraph_node *node;
- symtab_node snode;
struct lto_simple_output_block *ob
= lto_create_simple_output_block (LTO_section_ipa_reference);
unsigned int count = 0;
@@ -994,12 +992,10 @@ ipa_reference_write_optimization_summary (void)
/* See what variables we are interested in. */
for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
{
- struct varpool_node *vnode;
- snode = lto_symtab_encoder_deref (encoder, i);
- if (!symtab_variable_p (snode))
- continue;
- vnode = varpool (snode);
- if (bitmap_bit_p (all_module_statics, DECL_UID (vnode->symbol.decl))
+ symtab_node snode = lto_symtab_encoder_deref (encoder, i);
+ varpool_node *vnode = dyn_cast <varpool_node> (snode);
+ if (vnode
+ && bitmap_bit_p (all_module_statics, DECL_UID (vnode->symbol.decl))
&& referenced_from_this_partition_p (&vnode->symbol.ref_list, encoder))
{
tree decl = vnode->symbol.decl;
@@ -1013,10 +1009,12 @@ ipa_reference_write_optimization_summary (void)
if (ltrans_statics_bitcount)
for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
- if (symtab_function_p (snode = lto_symtab_encoder_deref (encoder, i))
- && write_node_summary_p (cgraph (snode),
- encoder, ltrans_statics))
+ {
+ symtab_node snode = lto_symtab_encoder_deref (encoder, i);
+ cgraph_node *cnode = dyn_cast <cgraph_node> (snode);
+ if (cnode && write_node_summary_p (cnode, encoder, ltrans_statics))
count++;
+ }
streamer_write_uhwi_stream (ob->main_stream, count);
if (count)
@@ -1027,17 +1025,15 @@ ipa_reference_write_optimization_summary (void)
if (ltrans_statics_bitcount)
for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
{
- snode = lto_symtab_encoder_deref (encoder, i);
- if (!symtab_function_p (snode))
- continue;
- node = cgraph (snode);
- if (write_node_summary_p (node, encoder, ltrans_statics))
+ symtab_node snode = lto_symtab_encoder_deref (encoder, i);
+ cgraph_node *cnode = dyn_cast <cgraph_node> (snode);
+ if (cnode && write_node_summary_p (cnode, encoder, ltrans_statics))
{
ipa_reference_optimization_summary_t info;
int node_ref;
- info = get_reference_optimization_summary (node);
- node_ref = lto_symtab_encoder_encode (encoder, (symtab_node) node);
+ info = get_reference_optimization_summary (cnode);
+ node_ref = lto_symtab_encoder_encode (encoder, snode);
streamer_write_uhwi_stream (ob->main_stream, node_ref);
stream_out_bitmap (ob, info->statics_not_read, ltrans_statics,