This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 5/5] Make ipa-sra observe the used parameter.


Hi,

On Thu, Jul 09, 2009 at 07:43:34PM +0200, Martin Jambor wrote:
> This  is to  a big  extent  an RFC  patch which  makes IPA-SRA  ignore
> parameters  decorated with  the  attribute "used."   Unlike the  other
> ones, it also needs an approval from a C front-end maintainer.
> 

In order to push this patch out  of an RFC state, I propose this patch
instead - the gcc  code is the same, I just needed  to update two more
testcases and also documented the change.

Thanks,

Martin

2009-07-10  Martin Jambor  <mjambor@suse.cz>

	* c-common.c (handle_used_attribute): Also accept the attribute on
	PARM_DECLs.
	* tree-sra.c (find_param_candidates): Do not consider parameters
	decorated with the used attribute.

	* doc/extend.texi: Describe what attribute used means when
	attached to parameters.

	* testsuite/gcc.dg/ipa/ipa-sra-5.c: New testsuite.  *
	* testsuite/gcc.dg/attr-invalid.c: Do not test invalid used
	attribute on parameters.
	* testsuite/gcc.dg/attr-nest.c: Test invalid externally_visible
	attribute rather than used attribute.

	
Index: mine/gcc/c-common.c
===================================================================
--- mine.orig/gcc/c-common.c
+++ mine/gcc/c-common.c
@@ -6030,6 +6030,7 @@ handle_used_attribute (tree *pnode, tree
   tree node = *pnode;
 
   if (TREE_CODE (node) == FUNCTION_DECL
+      || TREE_CODE (node) == PARM_DECL
       || (TREE_CODE (node) == VAR_DECL && TREE_STATIC (node)))
     {
       TREE_USED (node) = 1;
Index: mine/gcc/tree-sra.c
===================================================================
--- mine.orig/gcc/tree-sra.c
+++ mine/gcc/tree-sra.c
@@ -2691,7 +2691,8 @@ find_param_candidates (void)
 
       count++;
       if (TREE_THIS_VOLATILE (parm)
-	  || TREE_ADDRESSABLE (parm))
+	  || TREE_ADDRESSABLE (parm)
+	  || DECL_PRESERVE_P (parm))
 	continue;
 
       if (is_unused_scalar_param (parm))
Index: mine/gcc/testsuite/gcc.dg/ipa/ipa-sra-5.c
===================================================================
--- /dev/null
+++ mine/gcc/testsuite/gcc.dg/ipa/ipa-sra-5.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-eipa_sra-details" } */
+
+static int *
+__attribute__((noinline))
+  ox (int *i, __attribute__((used)) int *j)
+{
+  return i;
+}
+
+int a;
+
+int *caller (void)
+{
+  int b = 10;
+
+  return ox (&a, &b);
+}
+/* { dg-final { scan-tree-dump-times "base: j, remove_param" 0 "eipa_sra"  } } */
+/* { dg-final { cleanup-tree-dump "eipa_sra" } } */
Index: mine/gcc/testsuite/gcc.dg/attr-invalid.c
===================================================================
--- mine.orig/gcc/testsuite/gcc.dg/attr-invalid.c
+++ mine/gcc/testsuite/gcc.dg/attr-invalid.c
@@ -45,12 +45,6 @@ struct ATSYM(struct) {
 
 int ATSYM(var) ATTR;
 
-int ATSYM(fn_knrarg) (arg)
-  int arg ATTR; /* { dg-warning "attribute ignored" "" } */
-{ return 0; }
-
-int ATSYM(fn_isoarg) (int arg ATTR) { return 0; } /* { dg-warning "attribute ignored" "" } */
-
 int ATSYM(fn_vars) (void) {
   static int svar ATTR;
   auto int lvar ATTR; /* { dg-warning "attribute ignored" "" } */
Index: mine/gcc/testsuite/gcc.dg/attr-nest.c
===================================================================
--- mine.orig/gcc/testsuite/gcc.dg/attr-nest.c
+++ mine/gcc/testsuite/gcc.dg/attr-nest.c
@@ -1,7 +1,7 @@
 /* { dg-do compile } */
 
 #define ATTR_PRINTF __attribute__ ((format (printf, 1, 2)))
-#define ATTR_USED __attribute__ ((used))
+#define ATTR_USED __attribute__ ((externally_visible))
 
 void bar (int, ...);
 
Index: mine/gcc/doc/extend.texi
===================================================================
--- mine.orig/gcc/doc/extend.texi
+++ mine/gcc/doc/extend.texi
@@ -4071,8 +4071,10 @@ to be possibly unused.  GCC will not pro
 variable.
 
 @item used
-This attribute, attached to a variable, means that the variable must be
-emitted even if it appears that the variable is not referenced.
+This attribute, attached to a variable, means that the variable must
+be emitted even if it appears that the variable is not referenced.
+When attached to a function parameter, it means that the parameter
+must not be removed by optimizations such as IPA-SRA.
 
 @item vector_size (@var{bytes})
 This attribute specifies the vector size for the variable, measured in


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]