diff options
author | Nathan Sidwell <nathan@gcc.gnu.org> | 2004-08-19 10:36:07 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2004-08-19 10:36:07 +0000 |
commit | 89b0433e3a1f0a9ae590c1be5a6ba4b9aa690ae0 (patch) | |
tree | ba738aa254abf741ddc0722884b43575c2331ca6 /gcc/tree.c | |
parent | abc145a322be89c774fdcae8c883685d7943028a (diff) | |
download | gcc-89b0433e3a1f0a9ae590c1be5a6ba4b9aa690ae0.zip gcc-89b0433e3a1f0a9ae590c1be5a6ba4b9aa690ae0.tar.gz gcc-89b0433e3a1f0a9ae590c1be5a6ba4b9aa690ae0.tar.bz2 |
tree.h (TYPE_CACHED_VALUES_P): New.
* tree.h (TYPE_CACHED_VALUES_P): New.
(TYPE_CACHED_VALUES): New.
(TYPE_ORIG_SIZE_TYPE): Adjust.
* tree.def (INTEGER_CST): Update documentation.
* tree.c: Inlcude params.h.
(build_int_cst): Cache small values.
(build_type_copy): Do not copy the value cache.
* c-common.c (c_common_nodes_and_builtins): Add comment, remove
unneeded zeroing.
* c-typeck.c (build_c_cast): Add comment about OVERFLOW setting.
* expmed.c (const_mult_add_overflow_p): Clear type copy's value
cache.
* fold-const.c (force_fit_type): Copy value when setting
overflows.
(int_const_binop): Likewise.
* stor-layout.c: Include params.h
(set_sizetype): Create values cache.
(fixup_unsigned_type): Set UNSIGNED_P before caching any values.
* params.def (PARAM_INTEGER_SHARE_LIMIT): New.
* params.h (INTEGER_SHARE_LIMIT): New.
* Makefile.in (tree.o, stor-layout.o): Depend on PARAMS_H.
* cp/decl.c (finish_enum): Do not copy value node early, copy
later.
* cp/lex.c (cxx_init): Force null_node to be unique.
* java/parse.h (JAVA_RADIX10_FLAG): Rename to ...
(JAVA_NOT_RADIX10_FLAG): ... here. Invert meaning.
* java/lex.c (do_java_lex): Adjust.
(error_if_numeric_overflow): Likewise.
From-SVN: r86247
Diffstat (limited to 'gcc/tree.c')
-rw-r--r-- | gcc/tree.c | 80 |
1 files changed, 79 insertions, 1 deletions
@@ -48,6 +48,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "tree-iterator.h" #include "basic-block.h" #include "tree-flow.h" +#include "params.h" /* obstack.[ch] explicitly declined to prototype this. */ extern int _obstack_allocated_p (struct obstack *h, void *obj); @@ -427,15 +428,84 @@ tree build_int_cst (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi) { tree t; + int ix = -1; + int limit = 0; if (!type) type = integer_type_node; - + + switch (TREE_CODE (type)) + { + case POINTER_TYPE: + case REFERENCE_TYPE: + /* Cache NULL pointer. */ + if (!hi && !low) + { + limit = 1; + ix = 0; + } + break; + + case BOOLEAN_TYPE: + /* Cache false or true. */ + limit = 2; + if (!hi && low < 2) + ix = low; + break; + + case INTEGER_TYPE: + case CHAR_TYPE: + case OFFSET_TYPE: + if (TYPE_UNSIGNED (type)) + { + /* Cache 0..N */ + limit = INTEGER_SHARE_LIMIT; + if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT) + ix = low; + } + else + { + /* Cache -1..N */ + limit = INTEGER_SHARE_LIMIT + 1; + if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT) + ix = low + 1; + else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1) + ix = 0; + } + break; + default: + break; + } + + if (ix >= 0) + { + if (!TYPE_CACHED_VALUES_P (type)) + { + TYPE_CACHED_VALUES_P (type) = 1; + TYPE_CACHED_VALUES (type) = make_tree_vec (limit); + } + + t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix); + if (t) + { + /* Make sure no one is clobbering the shared constant. */ + if (TREE_TYPE (t) != type) + abort (); + if (TREE_INT_CST_LOW (t) != low || TREE_INT_CST_HIGH (t) != hi) + abort (); + return t; + } + } + t = make_node (INTEGER_CST); TREE_INT_CST_LOW (t) = low; TREE_INT_CST_HIGH (t) = hi; TREE_TYPE (t) = type; + + if (ix >= 0) + TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t; + return t; } @@ -3097,6 +3167,14 @@ build_type_copy (tree type) tree t, m = TYPE_MAIN_VARIANT (type); t = copy_node (type); + if (TYPE_CACHED_VALUES_P(t)) + { + /* Do not copy the values cache. */ + if (TREE_CODE (t) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t)) + abort (); + TYPE_CACHED_VALUES_P (t) = 0; + TYPE_CACHED_VALUES (t) = NULL_TREE; + } TYPE_POINTER_TO (t) = 0; TYPE_REFERENCE_TO (t) = 0; |