2002-02-01 18:16:02 +00:00
|
|
|
/* Perform optimizations on tree structure.
|
2007-05-19 01:19:51 +00:00
|
|
|
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005
|
2004-07-28 03:11:36 +00:00
|
|
|
Free Software Foundation, Inc.
|
2002-02-01 18:16:02 +00:00
|
|
|
Written by Mark Michell (mark@codesourcery.com).
|
|
|
|
|
2004-07-28 03:11:36 +00:00
|
|
|
This file is part of GCC.
|
2002-02-01 18:16:02 +00:00
|
|
|
|
2004-07-28 03:11:36 +00:00
|
|
|
GCC is free software; you can redistribute it and/or modify it
|
2002-02-01 18:16:02 +00:00
|
|
|
under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
2004-07-28 03:11:36 +00:00
|
|
|
GCC is distributed in the hope that it will be useful, but
|
2002-02-01 18:16:02 +00:00
|
|
|
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
|
2004-07-28 03:11:36 +00:00
|
|
|
along with GCC; see the file COPYING. If not, write to the Free
|
2007-05-19 01:19:51 +00:00
|
|
|
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
02110-1301, USA. */
|
2002-02-01 18:16:02 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "system.h"
|
2004-07-28 03:11:36 +00:00
|
|
|
#include "coretypes.h"
|
|
|
|
#include "tm.h"
|
2002-02-01 18:16:02 +00:00
|
|
|
#include "tree.h"
|
|
|
|
#include "cp-tree.h"
|
|
|
|
#include "rtl.h"
|
|
|
|
#include "insn-config.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "integrate.h"
|
|
|
|
#include "toplev.h"
|
|
|
|
#include "varray.h"
|
|
|
|
#include "params.h"
|
|
|
|
#include "hashtab.h"
|
2007-05-19 01:19:51 +00:00
|
|
|
#include "target.h"
|
2002-02-01 18:16:02 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "tree-inline.h"
|
2007-05-19 01:19:51 +00:00
|
|
|
#include "flags.h"
|
|
|
|
#include "langhooks.h"
|
|
|
|
#include "diagnostic.h"
|
|
|
|
#include "tree-dump.h"
|
|
|
|
#include "tree-gimple.h"
|
2002-02-01 18:16:02 +00:00
|
|
|
|
|
|
|
/* Prototypes. */
|
|
|
|
|
2007-05-19 01:19:51 +00:00
|
|
|
static void update_cloned_parm (tree, tree, bool);
|
2002-02-01 18:16:02 +00:00
|
|
|
|
|
|
|
/* CLONED_PARM is a copy of CLONE, generated for a cloned constructor
|
|
|
|
or destructor. Update it to ensure that the source-position for
|
|
|
|
the cloned parameter matches that for the original, and that the
|
|
|
|
debugging generation code will be able to find the original PARM. */
|
|
|
|
|
|
|
|
static void
|
2007-05-19 01:19:51 +00:00
|
|
|
update_cloned_parm (tree parm, tree cloned_parm, bool first)
|
2002-02-01 18:16:02 +00:00
|
|
|
{
|
|
|
|
DECL_ABSTRACT_ORIGIN (cloned_parm) = parm;
|
|
|
|
|
2003-07-11 03:40:53 +00:00
|
|
|
/* We may have taken its address. */
|
2002-02-01 18:16:02 +00:00
|
|
|
TREE_ADDRESSABLE (cloned_parm) = TREE_ADDRESSABLE (parm);
|
|
|
|
|
2003-07-11 03:40:53 +00:00
|
|
|
/* The definition might have different constness. */
|
2002-02-01 18:16:02 +00:00
|
|
|
TREE_READONLY (cloned_parm) = TREE_READONLY (parm);
|
2007-05-19 01:19:51 +00:00
|
|
|
|
|
|
|
TREE_USED (cloned_parm) = !first || TREE_USED (parm);
|
|
|
|
|
2003-07-11 03:40:53 +00:00
|
|
|
/* The name may have changed from the declaration. */
|
2002-02-01 18:16:02 +00:00
|
|
|
DECL_NAME (cloned_parm) = DECL_NAME (parm);
|
2003-07-11 03:40:53 +00:00
|
|
|
DECL_SOURCE_LOCATION (cloned_parm) = DECL_SOURCE_LOCATION (parm);
|
2007-05-19 01:19:51 +00:00
|
|
|
TREE_TYPE (cloned_parm) = TREE_TYPE (parm);
|
|
|
|
|
|
|
|
DECL_COMPLEX_GIMPLE_REG_P (cloned_parm) = DECL_COMPLEX_GIMPLE_REG_P (parm);
|
2002-02-01 18:16:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FN is a function that has a complete body. Clone the body as
|
2003-07-11 03:40:53 +00:00
|
|
|
necessary. Returns nonzero if there's no longer any need to
|
2002-02-01 18:16:02 +00:00
|
|
|
process the main body. */
|
|
|
|
|
2004-07-28 03:11:36 +00:00
|
|
|
bool
|
|
|
|
maybe_clone_body (tree fn)
|
2002-02-01 18:16:02 +00:00
|
|
|
{
|
|
|
|
tree clone;
|
2007-05-19 01:19:51 +00:00
|
|
|
bool first = true;
|
2002-02-01 18:16:02 +00:00
|
|
|
|
|
|
|
/* We only clone constructors and destructors. */
|
|
|
|
if (!DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
|
|
|
|
&& !DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Emit the DWARF1 abstract instance. */
|
|
|
|
(*debug_hooks->deferred_inline_function) (fn);
|
|
|
|
|
|
|
|
/* We know that any clones immediately follow FN in the TYPE_METHODS
|
|
|
|
list. */
|
2007-05-19 01:19:51 +00:00
|
|
|
push_to_top_level ();
|
|
|
|
FOR_EACH_CLONE (clone, fn)
|
2002-02-01 18:16:02 +00:00
|
|
|
{
|
|
|
|
tree parm;
|
|
|
|
tree clone_parm;
|
|
|
|
int parmno;
|
|
|
|
splay_tree decl_map;
|
|
|
|
|
|
|
|
/* Update CLONE's source position information to match FN's. */
|
2003-07-11 03:40:53 +00:00
|
|
|
DECL_SOURCE_LOCATION (clone) = DECL_SOURCE_LOCATION (fn);
|
2002-02-01 18:16:02 +00:00
|
|
|
DECL_INLINE (clone) = DECL_INLINE (fn);
|
|
|
|
DECL_DECLARED_INLINE_P (clone) = DECL_DECLARED_INLINE_P (fn);
|
|
|
|
DECL_COMDAT (clone) = DECL_COMDAT (fn);
|
|
|
|
DECL_WEAK (clone) = DECL_WEAK (fn);
|
|
|
|
DECL_ONE_ONLY (clone) = DECL_ONE_ONLY (fn);
|
|
|
|
DECL_SECTION_NAME (clone) = DECL_SECTION_NAME (fn);
|
|
|
|
DECL_USE_TEMPLATE (clone) = DECL_USE_TEMPLATE (fn);
|
|
|
|
DECL_EXTERNAL (clone) = DECL_EXTERNAL (fn);
|
|
|
|
DECL_INTERFACE_KNOWN (clone) = DECL_INTERFACE_KNOWN (fn);
|
|
|
|
DECL_NOT_REALLY_EXTERN (clone) = DECL_NOT_REALLY_EXTERN (fn);
|
|
|
|
TREE_PUBLIC (clone) = TREE_PUBLIC (fn);
|
2004-07-28 03:11:36 +00:00
|
|
|
DECL_VISIBILITY (clone) = DECL_VISIBILITY (fn);
|
2007-05-19 01:19:51 +00:00
|
|
|
DECL_VISIBILITY_SPECIFIED (clone) = DECL_VISIBILITY_SPECIFIED (fn);
|
2002-02-01 18:16:02 +00:00
|
|
|
|
2003-07-11 03:40:53 +00:00
|
|
|
/* Adjust the parameter names and locations. */
|
2002-02-01 18:16:02 +00:00
|
|
|
parm = DECL_ARGUMENTS (fn);
|
|
|
|
clone_parm = DECL_ARGUMENTS (clone);
|
|
|
|
/* Update the `this' parameter, which is always first. */
|
2007-05-19 01:19:51 +00:00
|
|
|
update_cloned_parm (parm, clone_parm, first);
|
2002-02-01 18:16:02 +00:00
|
|
|
parm = TREE_CHAIN (parm);
|
|
|
|
clone_parm = TREE_CHAIN (clone_parm);
|
|
|
|
if (DECL_HAS_IN_CHARGE_PARM_P (fn))
|
|
|
|
parm = TREE_CHAIN (parm);
|
|
|
|
if (DECL_HAS_VTT_PARM_P (fn))
|
|
|
|
parm = TREE_CHAIN (parm);
|
|
|
|
if (DECL_HAS_VTT_PARM_P (clone))
|
|
|
|
clone_parm = TREE_CHAIN (clone_parm);
|
|
|
|
for (; parm;
|
|
|
|
parm = TREE_CHAIN (parm), clone_parm = TREE_CHAIN (clone_parm))
|
2004-07-28 03:11:36 +00:00
|
|
|
/* Update this parameter. */
|
2007-05-19 01:19:51 +00:00
|
|
|
update_cloned_parm (parm, clone_parm, first);
|
2002-02-01 18:16:02 +00:00
|
|
|
|
|
|
|
/* Start processing the function. */
|
2007-05-19 01:19:51 +00:00
|
|
|
start_preparsed_function (clone, NULL_TREE, SF_PRE_PARSED);
|
2002-02-01 18:16:02 +00:00
|
|
|
|
|
|
|
/* Remap the parameters. */
|
|
|
|
decl_map = splay_tree_new (splay_tree_compare_pointers, NULL, NULL);
|
|
|
|
for (parmno = 0,
|
|
|
|
parm = DECL_ARGUMENTS (fn),
|
|
|
|
clone_parm = DECL_ARGUMENTS (clone);
|
|
|
|
parm;
|
|
|
|
++parmno,
|
|
|
|
parm = TREE_CHAIN (parm))
|
|
|
|
{
|
|
|
|
/* Map the in-charge parameter to an appropriate constant. */
|
|
|
|
if (DECL_HAS_IN_CHARGE_PARM_P (fn) && parmno == 1)
|
|
|
|
{
|
|
|
|
tree in_charge;
|
|
|
|
in_charge = in_charge_arg_for_name (DECL_NAME (clone));
|
|
|
|
splay_tree_insert (decl_map,
|
|
|
|
(splay_tree_key) parm,
|
|
|
|
(splay_tree_value) in_charge);
|
|
|
|
}
|
|
|
|
else if (DECL_ARTIFICIAL (parm)
|
|
|
|
&& DECL_NAME (parm) == vtt_parm_identifier)
|
|
|
|
{
|
|
|
|
/* For a subobject constructor or destructor, the next
|
|
|
|
argument is the VTT parameter. Remap the VTT_PARM
|
|
|
|
from the CLONE to this parameter. */
|
|
|
|
if (DECL_HAS_VTT_PARM_P (clone))
|
|
|
|
{
|
|
|
|
DECL_ABSTRACT_ORIGIN (clone_parm) = parm;
|
|
|
|
splay_tree_insert (decl_map,
|
|
|
|
(splay_tree_key) parm,
|
|
|
|
(splay_tree_value) clone_parm);
|
|
|
|
clone_parm = TREE_CHAIN (clone_parm);
|
|
|
|
}
|
|
|
|
/* Otherwise, map the VTT parameter to `NULL'. */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
splay_tree_insert (decl_map,
|
|
|
|
(splay_tree_key) parm,
|
|
|
|
(splay_tree_value) null_pointer_node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Map other parameters to their equivalents in the cloned
|
|
|
|
function. */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
splay_tree_insert (decl_map,
|
|
|
|
(splay_tree_key) parm,
|
|
|
|
(splay_tree_value) clone_parm);
|
|
|
|
clone_parm = TREE_CHAIN (clone_parm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-19 01:19:51 +00:00
|
|
|
if (targetm.cxx.cdtor_returns_this ())
|
|
|
|
{
|
|
|
|
parm = DECL_RESULT (fn);
|
|
|
|
clone_parm = DECL_RESULT (clone);
|
|
|
|
splay_tree_insert (decl_map, (splay_tree_key) parm,
|
|
|
|
(splay_tree_value) clone_parm);
|
|
|
|
}
|
2002-02-01 18:16:02 +00:00
|
|
|
/* Clone the body. */
|
|
|
|
clone_body (clone, fn, decl_map);
|
|
|
|
|
|
|
|
/* Clean up. */
|
|
|
|
splay_tree_delete (decl_map);
|
|
|
|
|
2003-07-11 03:40:53 +00:00
|
|
|
/* The clone can throw iff the original function can throw. */
|
|
|
|
cp_function_chain->can_throw = !TREE_NOTHROW (fn);
|
|
|
|
|
2002-02-01 18:16:02 +00:00
|
|
|
/* Now, expand this function into RTL, if appropriate. */
|
|
|
|
finish_function (0);
|
|
|
|
BLOCK_ABSTRACT_ORIGIN (DECL_INITIAL (clone)) = DECL_INITIAL (fn);
|
2004-07-28 03:11:36 +00:00
|
|
|
expand_or_defer_fn (clone);
|
2007-05-19 01:19:51 +00:00
|
|
|
first = false;
|
2002-02-01 18:16:02 +00:00
|
|
|
}
|
2007-05-19 01:19:51 +00:00
|
|
|
pop_from_top_level ();
|
2002-02-01 18:16:02 +00:00
|
|
|
|
|
|
|
/* We don't need to process the original function any further. */
|
|
|
|
return 1;
|
|
|
|
}
|