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: [tree-ssa] PATCH to gimplify_asm_expr for optimization/12525


Here's a followup patch to DTRT for mem ops by adding them to the
addresses_taken array.

Tested athlon-pc-linux-gnu, applied to tree-ssa.  stmt.c and tree.h hunks
also applied to the trunk.  The check_unique_operand_names hunk fixes
asm-6.c on tree-ssa.

2003-10-08  Jason Merrill  <jason@redhat.com>

	* tree-dfa.c (note_addressable): New fn, split out from...
	(add_stmt_operands): Here.
	(get_stmt_operands) <ASM_EXPR>: Call it for mem ops.
	* gimplify.c (gimplify_asm_expr): Call parse_input_constraint
	directly.  It's only a mem op if allows_mem is set.

	* stmt.c (resolve_asm_operand_names): Call check_unique_operand_names 
	here.
	(expand_asm_operands): Not here.
	(parse_input_constraint): No longer static.
	* tree.h: Declare it.

*** gimplify.c.~1~	2003-10-08 06:27:50.000000000 -0400
--- gimplify.c	2003-10-08 19:01:30.000000000 -0400
*************** gimplify_addr_expr (tree *expr_p, tree *
*** 2161,2168 ****
--- 2161,2173 ----
  static void
  gimplify_asm_expr (tree expr, tree *pre_p, tree *post_p)
  {
+   int noutputs = list_length (ASM_OUTPUTS (expr));
+   const char **oconstraints
+     = (const char **) alloca ((noutputs) * sizeof (const char *));
    int i;
    tree link;
+   const char *constraint;
+   bool allows_mem, allows_reg, is_inout;
  
    ASM_STRING (expr)
      = resolve_asm_operand_names (ASM_STRING (expr), ASM_OUTPUTS (expr),
*************** gimplify_asm_expr (tree expr, tree *pre_
*** 2170,2183 ****
  
    for (i = 0, link = ASM_OUTPUTS (expr); link; ++i, link = TREE_CHAIN (link))
      {
!       bool allows_reg, allows_mem, is_inout;
!       const char *constraint
  	= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
  
        parse_output_constraint (&constraint, i, 0, 0,
  			       &allows_mem, &allows_reg, &is_inout);
  
!       if (!allows_reg)
  	(*lang_hooks.mark_addressable) (TREE_VALUE (link));
  
        gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
--- 2175,2187 ----
  
    for (i = 0, link = ASM_OUTPUTS (expr); link; ++i, link = TREE_CHAIN (link))
      {
!       oconstraints[i] = constraint
  	= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
  
        parse_output_constraint (&constraint, i, 0, 0,
  			       &allows_mem, &allows_reg, &is_inout);
  
!       if (!allows_reg && allows_mem)
  	(*lang_hooks.mark_addressable) (TREE_VALUE (link));
  
        gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
*************** gimplify_asm_expr (tree expr, tree *pre_
*** 2207,2214 ****
  
    for (link = ASM_INPUTS (expr); link; link = TREE_CHAIN (link))
      {
        /* If the operand is a memory input, it should be an lvalue.  */
!       if (asm_op_is_mem_input (link, expr))
  	{
  	  (*lang_hooks.mark_addressable) (TREE_VALUE (link));
  	  gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
--- 2211,2223 ----
  
    for (link = ASM_INPUTS (expr); link; link = TREE_CHAIN (link))
      {
+       constraint
+ 	= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
+       parse_input_constraint (&constraint, 0, 0, noutputs, 0,
+ 			      oconstraints, &allows_mem, &allows_reg);
+ 
        /* If the operand is a memory input, it should be an lvalue.  */
!       if (!allows_reg && allows_mem)
  	{
  	  (*lang_hooks.mark_addressable) (TREE_VALUE (link));
  	  gimplify_expr (&TREE_VALUE (link), pre_p, post_p,
*** stmt.c.~1~	2003-10-08 06:27:50.000000000 -0400
--- stmt.c	2003-10-08 12:50:32.000000000 -0400
*************** struct stmt_status GTY(())
*** 391,398 ****
  int using_eh_for_cleanups_p = 0;
  
  static int n_occurrences (int, const char *);
- static bool parse_input_constraint (const char **, int, int, int, int,
- 				    const char * const *, bool *, bool *);
  static bool decl_conflicts_with_clobbers_p (tree, const HARD_REG_SET);
  static void expand_goto_internal (tree, rtx, rtx);
  static int expand_fixup (tree, rtx, rtx);
--- 391,396 ----
*************** parse_output_constraint (const char **co
*** 1253,1259 ****
  
  /* Similar, but for input constraints.  */
  
! static bool
  parse_input_constraint (const char **constraint_p, int input_num,
  			int ninputs, int noutputs, int ninout,
  			const char * const * constraints,
--- 1251,1257 ----
  
  /* Similar, but for input constraints.  */
  
! bool
  parse_input_constraint (const char **constraint_p, int input_num,
  			int ninputs, int noutputs, int ninout,
  			const char * const * constraints,
*************** expand_asm_operands (tree string, tree o
*** 1492,1500 ****
    if (! check_operand_nalternatives (outputs, inputs))
      return;
  
-   if (! check_unique_operand_names (outputs, inputs))
-     return;
- 
    string = resolve_asm_operand_names (string, outputs, inputs);
  
    /* Collect constraints.  */
--- 1490,1495 ----
*************** resolve_asm_operand_names (tree string, 
*** 2048,2053 ****
--- 2043,2050 ----
    const char *c;
    tree t;
  
+   check_unique_operand_names (outputs, inputs);
+ 
    /* Substitute [<name>] in input constraint strings.  There should be no
       named operands in output constraints.  */
    for (t = inputs; t ; t = TREE_CHAIN (t))
*** tree-dfa.c.~1~	2003-10-08 06:27:50.000000000 -0400
--- tree-dfa.c	2003-10-08 19:00:47.000000000 -0400
*************** struct dfa_stats_d dfa_stats;
*** 123,128 ****
--- 123,129 ----
  
  
  /* Local functions.  */
+ static void note_addressable (tree, stmt_ann_t);
  static void cleanup_operand_arrays (stmt_ann_t);
  static void get_expr_operands (tree, tree *, int, voperands_t);
  static void collect_dfa_stats (struct dfa_stats_d *);
*************** get_stmt_operands (tree stmt)
*** 225,233 ****
        break;
  
      case ASM_EXPR:
!       get_expr_operands (stmt, &ASM_INPUTS (stmt), 0, prev_vops);
!       get_expr_operands (stmt, &ASM_OUTPUTS (stmt), opf_is_def, prev_vops);
!       get_expr_operands (stmt, &ASM_CLOBBERS (stmt), opf_is_def, prev_vops);
        break;
  
      case RETURN_EXPR:
--- 226,266 ----
        break;
  
      case ASM_EXPR:
!       {
! 	int noutputs = list_length (ASM_OUTPUTS (stmt));
! 	const char **oconstraints
! 	  = (const char **) alloca ((noutputs) * sizeof (const char *));
! 	int i;
! 	tree link;
! 	const char *constraint;
! 	bool allows_mem, allows_reg, is_inout;
! 
! 	for (i=0, link = ASM_OUTPUTS (stmt); link;
! 	     ++i, link = TREE_CHAIN (link))
! 	  {
! 	    oconstraints[i] = constraint
! 	      = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
! 	    parse_output_constraint (&constraint, i, 0, 0,
! 				     &allows_mem, &allows_reg, &is_inout);
! 	    if (allows_reg && is_inout)
! 	      /* This should have been split in gimplify_asm_expr.  */
! 	      abort ();
! 	    if (!allows_reg && allows_mem)
! 	      note_addressable (TREE_VALUE (link), ann);
! 	    get_expr_operands (stmt, &TREE_VALUE (link), opf_is_def,
! 			       prev_vops);
! 	  }
! 	for (link = ASM_INPUTS (stmt); link; link = TREE_CHAIN (link))
! 	  {
! 	    constraint
! 	      = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
! 	    parse_input_constraint (&constraint, 0, 0, noutputs, 0,
! 				    oconstraints, &allows_mem, &allows_reg);
! 	    if (!allows_reg && allows_mem)
! 	      note_addressable (TREE_VALUE (link), ann);
! 	    get_expr_operands (stmt, &TREE_VALUE (link), 0, prev_vops);
! 	  }
!       }
        break;
  
      case RETURN_EXPR:
*************** add_stmt_operand (tree *var_p, tree stmt
*** 545,558 ****
       variables that have had their address taken in this statement.  */
    if (TREE_CODE (var) == ADDR_EXPR)
      {
!       var = get_base_symbol (TREE_OPERAND (var, 0));
!       if (var && SSA_VAR_P (var))
! 	{
! 	  if (s_ann->addresses_taken == NULL)
! 	    VARRAY_TREE_INIT (s_ann->addresses_taken, 2, "addresses_taken");
! 	  VARRAY_PUSH_TREE (s_ann->addresses_taken, var);
! 	}
! 
        return;
      }
  
--- 578,584 ----
       variables that have had their address taken in this statement.  */
    if (TREE_CODE (var) == ADDR_EXPR)
      {
!       note_addressable (TREE_OPERAND (var, 0), s_ann);
        return;
      }
  
*************** add_stmt_operand (tree *var_p, tree stmt
*** 661,666 ****
--- 687,706 ----
      }
  }
  
+ /* Record that VAR had its address taken in the statement with annotations
+    S_ANN.  */
+ 
+ static void
+ note_addressable (tree var, stmt_ann_t s_ann)
+ {
+   var = get_base_symbol (var);
+   if (var && SSA_VAR_P (var))
+     {
+       if (s_ann->addresses_taken == NULL)
+ 	VARRAY_TREE_INIT (s_ann->addresses_taken, 2, "addresses_taken");
+       VARRAY_PUSH_TREE (s_ann->addresses_taken, var);
+     }
+ }
  
  /* Add DEF_P to the list of pointers to operands defined by STMT.  */
  
*** tree.h.~1~	2003-10-08 06:27:50.000000000 -0400
--- tree.h	2003-10-08 06:16:03.000000000 -0400
*************** extern void emit_nop (void);
*** 3382,3387 ****
--- 3382,3389 ----
  extern void expand_computed_goto (tree);
  extern bool parse_output_constraint (const char **, int, int, int,
  				     bool *, bool *, bool *);
+ extern bool parse_input_constraint (const char **, int, int, int, int,
+ 				    const char * const *, bool *, bool *);
  extern void expand_asm_operands (tree, tree, tree, tree, int, location_t);
  extern void expand_asm_expr (tree);
  extern bool asm_op_is_mem_input (tree, tree);

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