aboutsummaryrefslogtreecommitdiff
path: root/gcc/varpool.c
diff options
context:
space:
mode:
authorJan Hubicka <jh@suse.cz>2010-09-03 10:15:54 +0000
committerJan Hubicka <jh@suse.cz>2010-09-03 10:15:54 +0000
commit4cfcea75719e199a50339f52d7fafa4aa64755b7 (patch)
tree557b00c4e086e7d798393273321f3907a7d16cb4 /gcc/varpool.c
parent54c96f4d62e80bfb463f4367bca6710a0d2f87e2 (diff)
* cgraph.h (struct varpool_node): Add const_value_known.
(varpool_decide_const_value_known): Declare. * tree-ssa-ccp.c (fold_const_aggregate_ref): Update initializer folding. * lto-cgraph.c (lto_output_varpool_node): Store const_value_known. (input_varpool_node): Restore const_value_known. * tree-ssa-loop-ivcanon (constant_after_peeling): Check varpool for initializer folding. * ipa.c (ipa_discover_readonly_nonaddressable_var, function_and_variable_visibility): Compute const_value_known. * gimple-fold.c (get_symbol_constant_value): Use varpool for initializer folding. * varpool.c (varpool_decide_const_value_known): New function. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@163808 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/varpool.c')
-rw-r--r--gcc/varpool.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/gcc/varpool.c b/gcc/varpool.c
index 817a3197901..eac488fa79b 100644
--- a/gcc/varpool.c
+++ b/gcc/varpool.c
@@ -359,6 +359,37 @@ decide_is_variable_needed (struct varpool_node *node, tree decl)
return true;
}
+/* Return if NODE is constant and its initial value is known (so we can do
+ constant folding). The decision depends on whole program decisions
+ and can not be recomputed at ltrans stage for variables from other
+ partitions. For this reason the new value should be always combined
+ with the previous knowledge. */
+
+bool
+varpool_decide_const_value_known (struct varpool_node *node)
+{
+ tree decl = node->decl;
+
+ gcc_assert (TREE_STATIC (decl) || DECL_EXTERNAL (decl));
+ gcc_assert (TREE_CODE (decl) == VAR_DECL);
+ if (!TREE_READONLY (decl))
+ return false;
+ /* Variables declared 'const' without an initializer
+ have zero as the initializer if they may not be
+ overridden at link or run time. */
+ if (!DECL_INITIAL (decl)
+ && (DECL_EXTERNAL (decl)
+ || DECL_REPLACEABLE_P (decl)))
+ return false;
+
+ /* Variables declared `const' with an initializer are considered
+ to not be overwritable with different initializer by default.
+
+ ??? Previously we behaved so for scalar variables but not for array
+ accesses. */
+ return true;
+}
+
/* Mark DECL as finalized. By finalizing the declaration, frontend instruct the
middle end to output the variable to asm file, if needed or externally
visible. */