This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RFC: g++ aliasing (was: Re: g++ and aliasing bools)
- From: Dan Nicolaescu <dann at godzilla dot ICS dot UCI dot EDU>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Cc: Joe Buck <jbuck at synopsys dot com>, Mark Mitchell <mark at codesourcery dot com>, Daniel Berlin <dan at dberlin dot org>
- Date: Wed, 06 Mar 2002 11:28:26 -0800
- Subject: RFC: g++ aliasing (was: Re: g++ and aliasing bools)
The patch below should be feature complete wrt the previous discussion
on impoving alias analysis for the C++ compiler.
It provides support for inheritance and unions that was missing in the
previous patch.
I am not sure if vtables need some more special treatment. Comments on
that would be appreciated.
It bootstraps with no regressions on sparc-sun-solaris2.7 (excluding ada)
If you can run some C++ benchmarks please do tell if this patch makes
a difference.
Should I submit this patch for approval for inclusion in the mainline?
C++ alias analysis improvement.
* alias.c (record_component_aliases): Record aliases for base
classes too.
* cp/cp-lang.c (cxx_simple_enough_type): New function.
(cxx_get_alias_set): Use it.
*** alias.c.~1.166.~ Tue Mar 5 23:56:32 2002
--- alias.c Tue Mar 5 23:57:14 2002
***************
*** 679,684 ****
--- 679,694 ----
case RECORD_TYPE:
case UNION_TYPE:
case QUAL_UNION_TYPE:
+ /* Recursively record aliases for the base classes, if there are any */
+ if (TYPE_BINFO (type) != NULL && TYPE_BINFO_BASETYPES (type) != NULL)
+ {
+ int i;
+ for (i = 0; i < TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type)); i++)
+ {
+ tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (type), i);
+ record_alias_subset (superset, get_alias_set (BINFO_TYPE (binfo)));
+ }
+ }
for (field = TYPE_FIELDS (type); field != 0; field = TREE_CHAIN (field))
if (TREE_CODE (field) == FIELD_DECL && ! DECL_NONADDRESSABLE_P (field))
record_alias_subset (superset, get_alias_set (TREE_TYPE (field)));
Index: cp-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-lang.c,v
retrieving revision 1.10
diff -c -3 -p -c -r1.10 cp-lang.c
*** cp-lang.c 2002/02/28 07:39:37 1.10
--- cp-lang.c 2002/03/06 18:25:07
*************** static HOST_WIDE_INT cxx_get_alias_set P
*** 97,112 ****
/* Each front end provides its own hooks, for toplev.c. */
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
/* Special routine to get the alias set for C++. */
static HOST_WIDE_INT
cxx_get_alias_set (t)
tree t;
{
! /* It's not yet safe to use alias sets for classes in C++ because
! the TYPE_FIELDs list for a class doesn't mention base classes. */
! if (AGGREGATE_TYPE_P (t))
return 0;
!
return c_common_get_alias_set (t);
}
--- 97,193 ----
/* Each front end provides its own hooks, for toplev.c. */
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
+ /* Check if a C++ type is safe for aliasing.
+ PODs are safe.
+ Classes with virtual bases are not safe.
+ All the members of a class should be safe. */
+
+ static bool
+ cxx_simple_enough_type (t)
+ tree t;
+ {
+ if (AGGREGATE_TYPE_P (t))
+ {
+ if ((TREE_CODE (t) == RECORD_TYPE) || (TREE_CODE (t) == UNION_TYPE))
+ {
+ tree fields;
+ /* PODs are safe */
+ if (! CLASSTYPE_NON_POD_P(t))
+ return true;
+ /* classes with virtual baseclasses are not */
+ if (TYPE_USES_VIRTUAL_BASECLASSES (t))
+ return false;
+ for (fields = TYPE_FIELDS (t); fields; fields = TREE_CHAIN (fields))
+ {
+ if (TREE_CODE (fields) != FIELD_DECL)
+ continue;
+ if (! cxx_simple_enough_type (TREE_TYPE (fields)))
+ return false;
+ }
+ return true;
+ }
+ else if (TREE_CODE (t) == ARRAY_TYPE)
+ return cxx_simple_enough_type (TREE_TYPE (t));
+ else
+ return false;
+ }
+ else
+ return true;
+ }
+
/* Special routine to get the alias set for C++. */
static HOST_WIDE_INT
cxx_get_alias_set (t)
tree t;
{
! /* It's not yet safe to use alias sets for some classes in C++ */
! if (!cxx_simple_enough_type(t))
return 0;
!
return c_common_get_alias_set (t);
}