* gimple.h: Remove all includes. (recalculate_side_effects): Move prototype to gimplify.h. * Makefile.in (PLUGIN_HEADERS): Add flattened gimple.h includes. * gengtype.c (open_base_files): Add gimple.h include list. * gimplify.h (recalculate_side_effects): Relocate prototype here. * gimple.c: Adjust include list. (recalculate_side_effects): Move to gimplify.c. * gimplify.c: Adjust include list. (recalculate_side_effects): Relocate from gimple.c. * alias.c: Add required include files removed from gimple.h. * asan.c: Likewise. * builtins.c: Likewise. * calls.c: Likewise. * cfgexpand.c: Likewise. * cfgloop.c: Likewise. * cfgloopmanip.c: Likewise. * cgraphbuild.c: Likewise. * cgraph.c: Likewise. * cgraphclones.c: Likewise. * cgraphunit.c: Likewise. * cilk-common.c: Likewise. * data-streamer.c: Likewise. * data-streamer-in.c: Likewise. * data-streamer-out.c: Likewise. * dse.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * fold-const.c: Likewise. * function.c: Likewise. * gimple-builder.c: Likewise. * gimple-expr.c: Likewise. * gimple-fold.c: Likewise. * gimple-iterator.c: Likewise. * gimple-low.c: Likewise. * gimple-pretty-print.c: Likewise. * gimple-ssa-isolate-paths.c: Likewise. * gimple-ssa-strength-reduction.c: Likewise. * gimple-streamer-in.c: Likewise. * gimple-streamer-out.c: Likewise. * gimple-walk.c: Likewise. * gimplify-me.c: Likewise. * graphite-blocking.c: Likewise. * graphite.c: Likewise. * graphite-clast-to-gimple.c: Likewise. * graphite-dependences.c: Likewise. * graphite-interchange.c: Likewise. * graphite-optimize-isl.c: Likewise. * graphite-poly.c: Likewise. * graphite-scop-detection.c: Likewise. * graphite-sese-to-poly.c: Likewise. * internal-fn.c: Likewise. * ipa.c: Likewise. * ipa-cp.c: Likewise. * ipa-devirt.c: Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline.c: Likewise. * ipa-profile.c: Likewise. * ipa-prop.c: Likewise. * ipa-pure-const.c: Likewise. * ipa-reference.c: Likewise. * ipa-split.c: Likewise. * ipa-utils.c: Likewise. * langhooks.c: Likewise. * lto-cgraph.c: Likewise. * lto-compress.c: Likewise. * lto-opts.c: Likewise. * lto-section-in.c: Likewise. * lto-section-out.c: Likewise. * lto-streamer.c: Likewise. * lto-streamer-in.c: Likewise. * lto-streamer-out.c: Likewise. * omp-low.c: Likewise. * opts-global.c: Likewise. * passes.c: Likewise. * predict.c: Likewise. * profile.c: Likewise. * sese.c: Likewise. * stmt.c: Likewise. * stor-layout.c: Likewise. * symtab.c: Likewise. * targhooks.c: Likewise. * toplev.c: Likewise. * tracer.c: Likewise. * trans-mem.c: Likewise. * tree-affine.c: Likewise. * tree.c: Likewise. * tree-call-cdce.c: Likewise. * tree-cfg.c: Likewise. * tree-cfgcleanup.c: Likewise. * tree-chrec.c: Likewise. * tree-complex.c: Likewise. * tree-data-ref.c: Likewise. * tree-dfa.c: Likewise. * tree-eh.c: Likewise. * tree-emutls.c: Likewise. * tree-if-conv.c: Likewise. * tree-inline.c: Likewise. * tree-into-ssa.c: Likewise. * tree-loop-distribution.c: Likewise. * tree-nested.c: Likewise. * tree-nrv.c: Likewise. * tree-object-size.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-predcom.c: Likewise. * tree-pretty-print.c: Likewise. * tree-profile.c: Likewise. * tree-scalar-evolution.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-address.c: Likewise. * tree-ssa-alias.c: Likewise. * tree-ssa.c: Likewise. * tree-ssa-ccp.c: Likewise. * tree-ssa-coalesce.c: Likewise. * tree-ssa-copy.c: Likewise. * tree-ssa-copyrename.c: Likewise. * tree-ssa-dce.c: Likewise. * tree-ssa-dom.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-ssa-forwprop.c: Likewise. * tree-ssa-ifcombine.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop.c: Likewise. * tree-ssa-loop-ch.c: Likewise. * tree-ssa-loop-im.c: Likewise. * tree-ssa-loop-ivcanon.c: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-loop-prefetch.c: Likewise. * tree-ssa-loop-unswitch.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssanames.c: Likewise. * tree-ssa-operands.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-pre.c: Likewise. * tree-ssa-propagate.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-sink.c: Likewise. * tree-ssa-strlen.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-ssa-tail-merge.c: Likewise. * tree-ssa-ter.c: Likewise. * tree-ssa-threadedge.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa-uncprop.c: Likewise. * tree-ssa-uninit.c: Likewise. * tree-stdarg.c: Likewise. * tree-streamer.c: Likewise. * tree-streamer-in.c: Likewise. * tree-streamer-out.c: Likewise. * tree-switch-conversion.c: Likewise. * tree-tailcall.c: Likewise. * tree-vect-data-refs.c: Likewise. * tree-vect-generic.c: Likewise. * tree-vect-loop.c: Likewise. * tree-vect-loop-manip.c: Likewise. * tree-vectorizer.c: Likewise. * tree-vect-patterns.c: Likewise. * tree-vect-slp.c: Likewise. * tree-vect-stmts.c: Likewise. * tree-vrp.c: Likewise. * tsan.c: Likewise. * ubsan.c: Likewise. * value-prof.c: Likewise. * varpool.c: Likewise. * var-tracking.c: Likewise. * vtable-verify.c: Likewise. * ada/gcc-interface/trans.c: Add required include files from gimple.h. * c/c-typeck.c: Add required include files from gimple.h. * c-family/c-common.c: Add required include files from gimple.h. * c-family/c-gimplify.c: Likewise * c-family/cilk.c: Likewise * cp/class.c: Add required include files from gimple.h. * cp/cp-gimplify.c: Likewise * cp/decl2.c: Likewise * cp/init.c: Likewise * cp/optimize.c: Likewise * cp/pt.c: Likewise * cp/semantics.c: Likewise * cp/tree.c: Likewise * cp/typeck.c: Likewise * cp/vtable-class-hierarchy.c: Likewise * fortran/trans.c: Add required include files from gimple.h. * fortran/trans-expr.c: Likewise * fortran/trans-openmp.c: Likewise * go/gofrontend/expressions.cc: Add required include files from gimple.h. * go/gofrontend/gogo-tree.cc: Likewise * go/gofrontend/types.cc: Likewise * go/go-gcc.cc: Likewise * go/go-lang.c: Likewise * java/java-gimplify.c: Add required include files from gimple.h. * lto/lto.c: Add required include files from gimple.h. * lto/lto-lang.c: Likewise * lto/lto-object.c: Likewise * lto/lto-partition.c: Likewise * lto/lto-symtab.c: Likewise * objc/objc-act.c: Add required include files from gimple.h. * config/darwin.c: Add required include files removed from gimple.h. * config/aarch64/aarch64-builtins.c: Likewise. * config/aarch64/aarch64.c: Likewise. * config/alpha/alpha.c: Likewise. * config/i386/i386.c: Likewise. * config/i386/winnt.c: Likewise. * config/ia64/ia64.c: Likewise. * config/m32c/m32c.c: Likewise. * config/mep/mep.c: Likewise. * config/mips/mips.c: Likewise. * config/rs6000/rs6000.c: Likewise. * config/s390/s390.c: Likewise. * config/sh/sh.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/tilegx/tilegx.c: Likewise. * config/tilepro/tilepro.c: Likewise. * config/xtensa/xtensa.c: Likewise. * testsuite/gcc.dg/plugin/finish_unit_plugin.c: Add required include files removed from gimple.h. * testsuite/gcc.dg/plugin/ggcplug.c: Likewise. * testsuite/gcc.dg/plugin/one_time_plugin.c: Likewise. * testsuite/gcc.dg/plugin/selfassign.c: Likewise. * testsuite/gcc.dg/plugin/start_unit_plugin.c: Likewise. * testsuite/g++.dg/plugin/selfassign.c: Likewise. From-SVN: r205272
364 lines
10 KiB
C
364 lines
10 KiB
C
/* Miscellaneous utilities for tree streaming. Things that are used
|
|
in both input and output are here.
|
|
|
|
Copyright (C) 2011-2013 Free Software Foundation, Inc.
|
|
Contributed by Diego Novillo <dnovillo@google.com>
|
|
|
|
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/>. */
|
|
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#include "coretypes.h"
|
|
#include "tree.h"
|
|
#include "basic-block.h"
|
|
#include "tree-ssa-alias.h"
|
|
#include "internal-fn.h"
|
|
#include "gimple-expr.h"
|
|
#include "is-a.h"
|
|
#include "gimple.h"
|
|
#include "streamer-hooks.h"
|
|
#include "tree-streamer.h"
|
|
|
|
/* Check that all the TS_* structures handled by the streamer_write_* and
|
|
streamer_read_* routines are exactly ALL the structures defined in
|
|
treestruct.def. */
|
|
|
|
void
|
|
streamer_check_handled_ts_structures (void)
|
|
{
|
|
bool handled_p[LAST_TS_ENUM];
|
|
unsigned i;
|
|
|
|
memset (&handled_p, 0, sizeof (handled_p));
|
|
|
|
/* These are the TS_* structures that are either handled or
|
|
explicitly ignored by the streamer routines. */
|
|
handled_p[TS_BASE] = true;
|
|
handled_p[TS_TYPED] = true;
|
|
handled_p[TS_COMMON] = true;
|
|
handled_p[TS_INT_CST] = true;
|
|
handled_p[TS_REAL_CST] = true;
|
|
handled_p[TS_FIXED_CST] = true;
|
|
handled_p[TS_VECTOR] = true;
|
|
handled_p[TS_STRING] = true;
|
|
handled_p[TS_COMPLEX] = true;
|
|
handled_p[TS_IDENTIFIER] = true;
|
|
handled_p[TS_DECL_MINIMAL] = true;
|
|
handled_p[TS_DECL_COMMON] = true;
|
|
handled_p[TS_DECL_WRTL] = true;
|
|
handled_p[TS_DECL_NON_COMMON] = true;
|
|
handled_p[TS_DECL_WITH_VIS] = true;
|
|
handled_p[TS_FIELD_DECL] = true;
|
|
handled_p[TS_VAR_DECL] = true;
|
|
handled_p[TS_PARM_DECL] = true;
|
|
handled_p[TS_LABEL_DECL] = true;
|
|
handled_p[TS_RESULT_DECL] = true;
|
|
handled_p[TS_CONST_DECL] = true;
|
|
handled_p[TS_TYPE_DECL] = true;
|
|
handled_p[TS_FUNCTION_DECL] = true;
|
|
handled_p[TS_TYPE_COMMON] = true;
|
|
handled_p[TS_TYPE_WITH_LANG_SPECIFIC] = true;
|
|
handled_p[TS_TYPE_NON_COMMON] = true;
|
|
handled_p[TS_LIST] = true;
|
|
handled_p[TS_VEC] = true;
|
|
handled_p[TS_EXP] = true;
|
|
handled_p[TS_SSA_NAME] = true;
|
|
handled_p[TS_BLOCK] = true;
|
|
handled_p[TS_BINFO] = true;
|
|
handled_p[TS_STATEMENT_LIST] = true;
|
|
handled_p[TS_CONSTRUCTOR] = true;
|
|
handled_p[TS_OMP_CLAUSE] = true;
|
|
handled_p[TS_OPTIMIZATION] = true;
|
|
handled_p[TS_TARGET_OPTION] = true;
|
|
handled_p[TS_TRANSLATION_UNIT_DECL] = true;
|
|
|
|
/* Anything not marked above will trigger the following assertion.
|
|
If this assertion triggers, it means that there is a new TS_*
|
|
structure that should be handled by the streamer. */
|
|
for (i = 0; i < LAST_TS_ENUM; i++)
|
|
gcc_assert (handled_p[i]);
|
|
}
|
|
|
|
|
|
/* Helper for streamer_tree_cache_insert_1. Add T to CACHE->NODES at
|
|
slot IX. */
|
|
|
|
static void
|
|
streamer_tree_cache_add_to_node_array (struct streamer_tree_cache_d *cache,
|
|
unsigned ix, tree t, hashval_t hash)
|
|
{
|
|
/* Make sure we're either replacing an old element or
|
|
appending consecutively. */
|
|
gcc_assert (ix <= cache->nodes.length ());
|
|
|
|
if (ix == cache->nodes.length ())
|
|
{
|
|
cache->nodes.safe_push (t);
|
|
if (cache->hashes.exists ())
|
|
cache->hashes.safe_push (hash);
|
|
}
|
|
else
|
|
{
|
|
cache->nodes[ix] = t;
|
|
if (cache->hashes.exists ())
|
|
cache->hashes[ix] = hash;
|
|
}
|
|
}
|
|
|
|
|
|
/* Helper for streamer_tree_cache_insert and streamer_tree_cache_insert_at.
|
|
CACHE, T, and IX_P are as in streamer_tree_cache_insert.
|
|
|
|
If INSERT_AT_NEXT_SLOT_P is true, T is inserted at the next available
|
|
slot in the cache. Otherwise, T is inserted at the position indicated
|
|
in *IX_P.
|
|
|
|
If T already existed in CACHE, return true. Otherwise,
|
|
return false. */
|
|
|
|
static bool
|
|
streamer_tree_cache_insert_1 (struct streamer_tree_cache_d *cache,
|
|
tree t, hashval_t hash, unsigned *ix_p,
|
|
bool insert_at_next_slot_p)
|
|
{
|
|
unsigned *slot;
|
|
unsigned ix;
|
|
bool existed_p;
|
|
|
|
gcc_assert (t);
|
|
|
|
slot = cache->node_map->insert (t, &existed_p);
|
|
if (!existed_p)
|
|
{
|
|
/* Determine the next slot to use in the cache. */
|
|
if (insert_at_next_slot_p)
|
|
ix = cache->nodes.length ();
|
|
else
|
|
ix = *ix_p;
|
|
*slot = ix;
|
|
|
|
streamer_tree_cache_add_to_node_array (cache, ix, t, hash);
|
|
}
|
|
else
|
|
{
|
|
ix = *slot;
|
|
|
|
if (!insert_at_next_slot_p && ix != *ix_p)
|
|
{
|
|
/* If the caller wants to insert T at a specific slot
|
|
location, and ENTRY->TO does not match *IX_P, add T to
|
|
the requested location slot. */
|
|
ix = *ix_p;
|
|
streamer_tree_cache_add_to_node_array (cache, ix, t, hash);
|
|
*slot = ix;
|
|
}
|
|
}
|
|
|
|
if (ix_p)
|
|
*ix_p = ix;
|
|
|
|
return existed_p;
|
|
}
|
|
|
|
|
|
/* Insert tree node T in CACHE. If T already existed in the cache
|
|
return true. Otherwise, return false.
|
|
|
|
If IX_P is non-null, update it with the index into the cache where
|
|
T has been stored. */
|
|
|
|
bool
|
|
streamer_tree_cache_insert (struct streamer_tree_cache_d *cache, tree t,
|
|
hashval_t hash, unsigned *ix_p)
|
|
{
|
|
return streamer_tree_cache_insert_1 (cache, t, hash, ix_p, true);
|
|
}
|
|
|
|
|
|
/* Replace the tree node with T in CACHE at slot IX. */
|
|
|
|
void
|
|
streamer_tree_cache_replace_tree (struct streamer_tree_cache_d *cache,
|
|
tree t, unsigned ix)
|
|
{
|
|
hashval_t hash = 0;
|
|
if (cache->hashes.exists ())
|
|
hash = streamer_tree_cache_get_hash (cache, ix);
|
|
if (!cache->node_map)
|
|
streamer_tree_cache_add_to_node_array (cache, ix, t, hash);
|
|
else
|
|
streamer_tree_cache_insert_1 (cache, t, hash, &ix, false);
|
|
}
|
|
|
|
|
|
/* Appends tree node T to CACHE, even if T already existed in it. */
|
|
|
|
void
|
|
streamer_tree_cache_append (struct streamer_tree_cache_d *cache,
|
|
tree t, hashval_t hash)
|
|
{
|
|
unsigned ix = cache->nodes.length ();
|
|
if (!cache->node_map)
|
|
streamer_tree_cache_add_to_node_array (cache, ix, t, hash);
|
|
else
|
|
streamer_tree_cache_insert_1 (cache, t, hash, &ix, false);
|
|
}
|
|
|
|
/* Return true if tree node T exists in CACHE, otherwise false. If IX_P is
|
|
not NULL, write to *IX_P the index into the cache where T is stored
|
|
((unsigned)-1 if T is not found). */
|
|
|
|
bool
|
|
streamer_tree_cache_lookup (struct streamer_tree_cache_d *cache, tree t,
|
|
unsigned *ix_p)
|
|
{
|
|
unsigned *slot;
|
|
bool retval;
|
|
unsigned ix;
|
|
|
|
gcc_assert (t);
|
|
|
|
slot = cache->node_map->contains (t);
|
|
if (slot == NULL)
|
|
{
|
|
retval = false;
|
|
ix = -1;
|
|
}
|
|
else
|
|
{
|
|
retval = true;
|
|
ix = *slot;
|
|
}
|
|
|
|
if (ix_p)
|
|
*ix_p = ix;
|
|
|
|
return retval;
|
|
}
|
|
|
|
|
|
/* Record NODE in CACHE. */
|
|
|
|
static void
|
|
record_common_node (struct streamer_tree_cache_d *cache, tree node)
|
|
{
|
|
/* If we recursively end up at nodes we do not want to preload simply don't.
|
|
??? We'd want to verify that this doesn't happen, or alternatively
|
|
do not recurse at all. */
|
|
if (node == char_type_node)
|
|
return;
|
|
|
|
gcc_checking_assert (node != boolean_type_node
|
|
&& node != boolean_true_node
|
|
&& node != boolean_false_node);
|
|
|
|
/* We have to make sure to fill exactly the same number of
|
|
elements for all frontends. That can include NULL trees.
|
|
As our hash table can't deal with zero entries we'll simply stream
|
|
a random other tree. A NULL tree never will be looked up so it
|
|
doesn't matter which tree we replace it with, just to be sure
|
|
use error_mark_node. */
|
|
if (!node)
|
|
node = error_mark_node;
|
|
|
|
/* ??? FIXME, devise a better hash value. But the hash needs to be equal
|
|
for all frontend and lto1 invocations. So just use the position
|
|
in the cache as hash value. */
|
|
streamer_tree_cache_append (cache, node, cache->nodes.length ());
|
|
|
|
if (POINTER_TYPE_P (node)
|
|
|| TREE_CODE (node) == COMPLEX_TYPE
|
|
|| TREE_CODE (node) == ARRAY_TYPE)
|
|
record_common_node (cache, TREE_TYPE (node));
|
|
else if (TREE_CODE (node) == RECORD_TYPE)
|
|
{
|
|
/* The FIELD_DECLs of structures should be shared, so that every
|
|
COMPONENT_REF uses the same tree node when referencing a field.
|
|
Pointer equality between FIELD_DECLs is used by the alias
|
|
machinery to compute overlapping component references (see
|
|
nonoverlapping_component_refs_p and
|
|
nonoverlapping_component_refs_of_decl_p). */
|
|
for (tree f = TYPE_FIELDS (node); f; f = TREE_CHAIN (f))
|
|
record_common_node (cache, f);
|
|
}
|
|
}
|
|
|
|
|
|
/* Preload common nodes into CACHE and make sure they are merged
|
|
properly according to the gimple type table. */
|
|
|
|
static void
|
|
preload_common_nodes (struct streamer_tree_cache_d *cache)
|
|
{
|
|
unsigned i;
|
|
|
|
for (i = 0; i < itk_none; i++)
|
|
/* Skip itk_char. char_type_node is dependent on -f[un]signed-char. */
|
|
if (i != itk_char)
|
|
record_common_node (cache, integer_types[i]);
|
|
|
|
for (i = 0; i < stk_type_kind_last; i++)
|
|
record_common_node (cache, sizetype_tab[i]);
|
|
|
|
for (i = 0; i < TI_MAX; i++)
|
|
/* Skip boolean type and constants, they are frontend dependent. */
|
|
if (i != TI_BOOLEAN_TYPE
|
|
&& i != TI_BOOLEAN_FALSE
|
|
&& i != TI_BOOLEAN_TRUE)
|
|
record_common_node (cache, global_trees[i]);
|
|
}
|
|
|
|
|
|
/* Create a cache of pickled nodes. */
|
|
|
|
struct streamer_tree_cache_d *
|
|
streamer_tree_cache_create (bool with_hashes, bool with_map)
|
|
{
|
|
struct streamer_tree_cache_d *cache;
|
|
|
|
cache = XCNEW (struct streamer_tree_cache_d);
|
|
|
|
if (with_map)
|
|
cache->node_map = new pointer_map<unsigned>;
|
|
cache->nodes.create (165);
|
|
if (with_hashes)
|
|
cache->hashes.create (165);
|
|
|
|
/* Load all the well-known tree nodes that are always created by
|
|
the compiler on startup. This prevents writing them out
|
|
unnecessarily. */
|
|
preload_common_nodes (cache);
|
|
|
|
return cache;
|
|
}
|
|
|
|
|
|
/* Delete the streamer cache C. */
|
|
|
|
void
|
|
streamer_tree_cache_delete (struct streamer_tree_cache_d *c)
|
|
{
|
|
if (c == NULL)
|
|
return;
|
|
|
|
if (c->node_map)
|
|
delete c->node_map;
|
|
c->nodes.release ();
|
|
c->hashes.release ();
|
|
free (c);
|
|
}
|