OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [ipa-prop.c] - Diff between revs 154 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
/* Interprocedural analyses.
/* Interprocedural analyses.
   Copyright (C) 2005, 2007 Free Software Foundation, Inc.
   Copyright (C) 2005, 2007 Free Software Foundation, Inc.
 
 
This file is part of GCC.
This file is part of GCC.
 
 
GCC is free software; you can redistribute it and/or modify it under
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
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
Software Foundation; either version 3, or (at your option) any later
version.
version.
 
 
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.
for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */
<http://www.gnu.org/licenses/>.  */
 
 
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#include "coretypes.h"
#include "coretypes.h"
#include "tree.h"
#include "tree.h"
#include "langhooks.h"
#include "langhooks.h"
#include "ggc.h"
#include "ggc.h"
#include "target.h"
#include "target.h"
#include "cgraph.h"
#include "cgraph.h"
#include "ipa-prop.h"
#include "ipa-prop.h"
#include "tree-flow.h"
#include "tree-flow.h"
#include "tree-pass.h"
#include "tree-pass.h"
#include "flags.h"
#include "flags.h"
#include "timevar.h"
#include "timevar.h"
 
 
/* This file contains interfaces that can be used for various IPA
/* This file contains interfaces that can be used for various IPA
   optimizations:
   optimizations:
 
 
   - ipa_methodlist interface - It is used to create and handle a temporary
   - ipa_methodlist interface - It is used to create and handle a temporary
   worklist used in  the propagation stage of IPCP. (can be used for more
   worklist used in  the propagation stage of IPCP. (can be used for more
   IPA optimizations).
   IPA optimizations).
 
 
   - ipa_callsite interface - for each callsite this interface creates and
   - ipa_callsite interface - for each callsite this interface creates and
   handles ipa_edge structure associated with it.
   handles ipa_edge structure associated with it.
 
 
   - ipa_method interface - for each method this interface creates and
   - ipa_method interface - for each method this interface creates and
   handles ipa_node structure associated with it.  */
   handles ipa_node structure associated with it.  */
 
 
/* ipa_methodlist interface.  */
/* ipa_methodlist interface.  */
 
 
/* Create a new worklist node.  */
/* Create a new worklist node.  */
static inline ipa_methodlist_p
static inline ipa_methodlist_p
ipa_create_methodlist_node (void)
ipa_create_methodlist_node (void)
{
{
  return (ipa_methodlist_p) xcalloc (1, sizeof (struct ipa_methodlist));
  return (ipa_methodlist_p) xcalloc (1, sizeof (struct ipa_methodlist));
}
}
 
 
/* Return true if worklist WL is empty.  */
/* Return true if worklist WL is empty.  */
bool
bool
ipa_methodlist_not_empty (ipa_methodlist_p wl)
ipa_methodlist_not_empty (ipa_methodlist_p wl)
{
{
  return (wl != NULL);
  return (wl != NULL);
}
}
 
 
/* Return the method in worklist element WL.  */
/* Return the method in worklist element WL.  */
static inline struct cgraph_node *
static inline struct cgraph_node *
ipa_methodlist_method (ipa_methodlist_p wl)
ipa_methodlist_method (ipa_methodlist_p wl)
{
{
  return wl->method_p;
  return wl->method_p;
}
}
 
 
/* Make worklist element WL point to method MT in the callgraph.  */
/* Make worklist element WL point to method MT in the callgraph.  */
static inline void
static inline void
ipa_methodlist_method_set (ipa_methodlist_p wl, struct cgraph_node *mt)
ipa_methodlist_method_set (ipa_methodlist_p wl, struct cgraph_node *mt)
{
{
  wl->method_p = mt;
  wl->method_p = mt;
}
}
 
 
/* Return the next element in the worklist following worklist
/* Return the next element in the worklist following worklist
   element WL.  */
   element WL.  */
static inline ipa_methodlist_p
static inline ipa_methodlist_p
ipa_methodlist_next_method (ipa_methodlist_p wl)
ipa_methodlist_next_method (ipa_methodlist_p wl)
{
{
  return wl->next_method;
  return wl->next_method;
}
}
 
 
/* Set worklist element WL1 to point to worklist element WL2.  */
/* Set worklist element WL1 to point to worklist element WL2.  */
static inline void
static inline void
ipa_methodlist_next_method_set (ipa_methodlist_p wl1, ipa_methodlist_p wl2)
ipa_methodlist_next_method_set (ipa_methodlist_p wl1, ipa_methodlist_p wl2)
{
{
  wl1->next_method = wl2;
  wl1->next_method = wl2;
}
}
 
 
/* Initialize worklist to contain all methods.  */
/* Initialize worklist to contain all methods.  */
ipa_methodlist_p
ipa_methodlist_p
ipa_methodlist_init (void)
ipa_methodlist_init (void)
{
{
  struct cgraph_node *node;
  struct cgraph_node *node;
  ipa_methodlist_p wl;
  ipa_methodlist_p wl;
 
 
  wl = NULL;
  wl = NULL;
  for (node = cgraph_nodes; node; node = node->next)
  for (node = cgraph_nodes; node; node = node->next)
    ipa_add_method (&wl, node);
    ipa_add_method (&wl, node);
 
 
  return wl;
  return wl;
}
}
 
 
/* Add method MT to the worklist. Set worklist element WL
/* Add method MT to the worklist. Set worklist element WL
   to point to MT.  */
   to point to MT.  */
void
void
ipa_add_method (ipa_methodlist_p * wl, struct cgraph_node *mt)
ipa_add_method (ipa_methodlist_p * wl, struct cgraph_node *mt)
{
{
  ipa_methodlist_p temp;
  ipa_methodlist_p temp;
 
 
  temp = ipa_create_methodlist_node ();
  temp = ipa_create_methodlist_node ();
  ipa_methodlist_method_set (temp, mt);
  ipa_methodlist_method_set (temp, mt);
  ipa_methodlist_next_method_set (temp, *wl);
  ipa_methodlist_next_method_set (temp, *wl);
  *wl = temp;
  *wl = temp;
}
}
 
 
/* Remove a method from the worklist. WL points to the first
/* Remove a method from the worklist. WL points to the first
   element in the list, which is removed.  */
   element in the list, which is removed.  */
struct cgraph_node *
struct cgraph_node *
ipa_remove_method (ipa_methodlist_p * wl)
ipa_remove_method (ipa_methodlist_p * wl)
{
{
  ipa_methodlist_p first;
  ipa_methodlist_p first;
  struct cgraph_node *return_method;
  struct cgraph_node *return_method;
 
 
  first = *wl;
  first = *wl;
  *wl = ipa_methodlist_next_method (*wl);
  *wl = ipa_methodlist_next_method (*wl);
  return_method = ipa_methodlist_method (first);
  return_method = ipa_methodlist_method (first);
  free (first);
  free (first);
  return return_method;
  return return_method;
}
}
 
 
/* ipa_method interface.  */
/* ipa_method interface.  */
 
 
/* Return number of formals of method MT.  */
/* Return number of formals of method MT.  */
int
int
ipa_method_formal_count (struct cgraph_node *mt)
ipa_method_formal_count (struct cgraph_node *mt)
{
{
  return IPA_NODE_REF (mt)->ipa_arg_num;
  return IPA_NODE_REF (mt)->ipa_arg_num;
}
}
 
 
/* Set number of formals of method MT to I.  */
/* Set number of formals of method MT to I.  */
void
void
ipa_method_formal_count_set (struct cgraph_node *mt, int i)
ipa_method_formal_count_set (struct cgraph_node *mt, int i)
{
{
  IPA_NODE_REF (mt)->ipa_arg_num = i;
  IPA_NODE_REF (mt)->ipa_arg_num = i;
}
}
 
 
/* Return whether I-th formal of MT is modified in MT.  */
/* Return whether I-th formal of MT is modified in MT.  */
static inline bool
static inline bool
ipa_method_is_modified (struct cgraph_node *mt, int i)
ipa_method_is_modified (struct cgraph_node *mt, int i)
{
{
  return IPA_NODE_REF (mt)->ipa_mod[i];
  return IPA_NODE_REF (mt)->ipa_mod[i];
}
}
 
 
/* Return the tree of I-th formal of MT.  */
/* Return the tree of I-th formal of MT.  */
tree
tree
ipa_method_get_tree (struct cgraph_node *mt, int i)
ipa_method_get_tree (struct cgraph_node *mt, int i)
{
{
  return IPA_NODE_REF (mt)->ipa_param_tree[i];
  return IPA_NODE_REF (mt)->ipa_param_tree[i];
}
}
 
 
/* Create tree map structure for MT.  */
/* Create tree map structure for MT.  */
static inline void
static inline void
ipa_method_tree_map_create (struct cgraph_node *mt)
ipa_method_tree_map_create (struct cgraph_node *mt)
{
{
  IPA_NODE_REF (mt)->ipa_param_tree =
  IPA_NODE_REF (mt)->ipa_param_tree =
    XCNEWVEC (tree, ipa_method_formal_count (mt));
    XCNEWVEC (tree, ipa_method_formal_count (mt));
}
}
 
 
/* Create modify structure for MT.  */
/* Create modify structure for MT.  */
static inline void
static inline void
ipa_method_modify_create (struct cgraph_node *mt)
ipa_method_modify_create (struct cgraph_node *mt)
{
{
  ((struct ipa_node *) mt->aux)->ipa_mod =
  ((struct ipa_node *) mt->aux)->ipa_mod =
    XCNEWVEC (bool, ipa_method_formal_count (mt));
    XCNEWVEC (bool, ipa_method_formal_count (mt));
}
}
 
 
/* Set modify of I-th formal of MT to VAL.  */
/* Set modify of I-th formal of MT to VAL.  */
static inline void
static inline void
ipa_method_modify_set (struct cgraph_node *mt, int i, bool val)
ipa_method_modify_set (struct cgraph_node *mt, int i, bool val)
{
{
  IPA_NODE_REF (mt)->ipa_mod[i] = val;
  IPA_NODE_REF (mt)->ipa_mod[i] = val;
}
}
 
 
/* Return index of the formal whose tree is PTREE in method MT.  */
/* Return index of the formal whose tree is PTREE in method MT.  */
static int
static int
ipa_method_tree_map (struct cgraph_node *mt, tree ptree)
ipa_method_tree_map (struct cgraph_node *mt, tree ptree)
{
{
  int i, count;
  int i, count;
 
 
  count = ipa_method_formal_count (mt);
  count = ipa_method_formal_count (mt);
  for (i = 0; i < count; i++)
  for (i = 0; i < count; i++)
    if (IPA_NODE_REF (mt)->ipa_param_tree[i] == ptree)
    if (IPA_NODE_REF (mt)->ipa_param_tree[i] == ptree)
      return i;
      return i;
 
 
  return -1;
  return -1;
}
}
 
 
/* Insert the formal trees to the ipa_param_tree array in method MT.  */
/* Insert the formal trees to the ipa_param_tree array in method MT.  */
void
void
ipa_method_compute_tree_map (struct cgraph_node *mt)
ipa_method_compute_tree_map (struct cgraph_node *mt)
{
{
  tree fndecl;
  tree fndecl;
  tree fnargs;
  tree fnargs;
  tree parm;
  tree parm;
  int param_num;
  int param_num;
 
 
  ipa_method_tree_map_create (mt);
  ipa_method_tree_map_create (mt);
  fndecl = mt->decl;
  fndecl = mt->decl;
  fnargs = DECL_ARGUMENTS (fndecl);
  fnargs = DECL_ARGUMENTS (fndecl);
  param_num = 0;
  param_num = 0;
  for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
  for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
    {
    {
      IPA_NODE_REF (mt)->ipa_param_tree[param_num] = parm;
      IPA_NODE_REF (mt)->ipa_param_tree[param_num] = parm;
      param_num++;
      param_num++;
    }
    }
}
}
 
 
/* Count number of formals in MT. Insert the result to the
/* Count number of formals in MT. Insert the result to the
   ipa_node.  */
   ipa_node.  */
void
void
ipa_method_formal_compute_count (struct cgraph_node *mt)
ipa_method_formal_compute_count (struct cgraph_node *mt)
{
{
  tree fndecl;
  tree fndecl;
  tree fnargs;
  tree fnargs;
  tree parm;
  tree parm;
  int param_num;
  int param_num;
 
 
  fndecl = mt->decl;
  fndecl = mt->decl;
  fnargs = DECL_ARGUMENTS (fndecl);
  fnargs = DECL_ARGUMENTS (fndecl);
  param_num = 0;
  param_num = 0;
  for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
  for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
    param_num++;
    param_num++;
  ipa_method_formal_count_set (mt, param_num);
  ipa_method_formal_count_set (mt, param_num);
}
}
 
 
/* Check STMT to detect whether a formal is modified within MT,
/* Check STMT to detect whether a formal is modified within MT,
   the appropriate entry is updated in the ipa_mod array of ipa_node
   the appropriate entry is updated in the ipa_mod array of ipa_node
   (associated with MT).  */
   (associated with MT).  */
static void
static void
ipa_method_modify_stmt (struct cgraph_node *mt, tree stmt)
ipa_method_modify_stmt (struct cgraph_node *mt, tree stmt)
{
{
  int i, j;
  int i, j;
 
 
  switch (TREE_CODE (stmt))
  switch (TREE_CODE (stmt))
    {
    {
    case MODIFY_EXPR:
    case MODIFY_EXPR:
      if (TREE_CODE (TREE_OPERAND (stmt, 0)) == PARM_DECL)
      if (TREE_CODE (TREE_OPERAND (stmt, 0)) == PARM_DECL)
        {
        {
          i = ipa_method_tree_map (mt, TREE_OPERAND (stmt, 0));
          i = ipa_method_tree_map (mt, TREE_OPERAND (stmt, 0));
          if (i >= 0)
          if (i >= 0)
            ipa_method_modify_set (mt, i, true);
            ipa_method_modify_set (mt, i, true);
        }
        }
      break;
      break;
    case ASM_EXPR:
    case ASM_EXPR:
      /* Asm code could modify any of the parameters.  */
      /* Asm code could modify any of the parameters.  */
      for (j = 0; j < ipa_method_formal_count (mt); j++)
      for (j = 0; j < ipa_method_formal_count (mt); j++)
        ipa_method_modify_set (mt, j, true);
        ipa_method_modify_set (mt, j, true);
      break;
      break;
    default:
    default:
      break;
      break;
    }
    }
}
}
 
 
/* Initialize ipa_mod array of MT.  */
/* Initialize ipa_mod array of MT.  */
static void
static void
ipa_method_modify_init (struct cgraph_node *mt)
ipa_method_modify_init (struct cgraph_node *mt)
{
{
  int i, count;
  int i, count;
 
 
  ipa_method_modify_create (mt);
  ipa_method_modify_create (mt);
  count = ipa_method_formal_count (mt);
  count = ipa_method_formal_count (mt);
  for (i = 0; i < count; i++)
  for (i = 0; i < count; i++)
    ipa_method_modify_set (mt, i, false);
    ipa_method_modify_set (mt, i, false);
}
}
 
 
/* The modify computation driver for MT. Compute which formal arguments
/* The modify computation driver for MT. Compute which formal arguments
   of method MT are locally modified.  Formals may be modified in MT
   of method MT are locally modified.  Formals may be modified in MT
   if their address is taken, or if
   if their address is taken, or if
   they appear on the left hand side of an assignment.  */
   they appear on the left hand side of an assignment.  */
void
void
ipa_method_compute_modify (struct cgraph_node *mt)
ipa_method_compute_modify (struct cgraph_node *mt)
{
{
  tree decl;
  tree decl;
  tree body;
  tree body;
  int j, count;
  int j, count;
  basic_block bb;
  basic_block bb;
  struct function *func;
  struct function *func;
  block_stmt_iterator bsi;
  block_stmt_iterator bsi;
  tree stmt, parm_tree;
  tree stmt, parm_tree;
 
 
  ipa_method_modify_init (mt);
  ipa_method_modify_init (mt);
  decl = mt->decl;
  decl = mt->decl;
  count = ipa_method_formal_count (mt);
  count = ipa_method_formal_count (mt);
  /* ??? Handle pending sizes case. Set all parameters
  /* ??? Handle pending sizes case. Set all parameters
     of the method to be modified.  */
     of the method to be modified.  */
  if (DECL_UNINLINABLE (decl))
  if (DECL_UNINLINABLE (decl))
    {
    {
      for (j = 0; j < count; j++)
      for (j = 0; j < count; j++)
        ipa_method_modify_set (mt, j, true);
        ipa_method_modify_set (mt, j, true);
      return;
      return;
    }
    }
  /* Formals whose address is taken are considered modified.  */
  /* Formals whose address is taken are considered modified.  */
  for (j = 0; j < count; j++)
  for (j = 0; j < count; j++)
    {
    {
      parm_tree = ipa_method_get_tree (mt, j);
      parm_tree = ipa_method_get_tree (mt, j);
      if (TREE_ADDRESSABLE (parm_tree))
      if (TREE_ADDRESSABLE (parm_tree))
        ipa_method_modify_set (mt, j, true);
        ipa_method_modify_set (mt, j, true);
    }
    }
  body = DECL_SAVED_TREE (decl);
  body = DECL_SAVED_TREE (decl);
  if (body != NULL)
  if (body != NULL)
    {
    {
      func = DECL_STRUCT_FUNCTION (decl);
      func = DECL_STRUCT_FUNCTION (decl);
      FOR_EACH_BB_FN (bb, func)
      FOR_EACH_BB_FN (bb, func)
      {
      {
        for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
        for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
          {
          {
            stmt = bsi_stmt (bsi);
            stmt = bsi_stmt (bsi);
            ipa_method_modify_stmt (mt, stmt);
            ipa_method_modify_stmt (mt, stmt);
          }
          }
      }
      }
    }
    }
}
}
 
 
 
 
/* ipa_callsite interface.  */
/* ipa_callsite interface.  */
 
 
/* Return number of arguments in callsite CS.  */
/* Return number of arguments in callsite CS.  */
int
int
ipa_callsite_param_count (struct cgraph_edge *cs)
ipa_callsite_param_count (struct cgraph_edge *cs)
{
{
  return IPA_EDGE_REF (cs)->ipa_param_num;
  return IPA_EDGE_REF (cs)->ipa_param_num;
}
}
 
 
/* Set number of arguments in callsite CS to I.  */
/* Set number of arguments in callsite CS to I.  */
void
void
ipa_callsite_param_count_set (struct cgraph_edge *cs, int i)
ipa_callsite_param_count_set (struct cgraph_edge *cs, int i)
{
{
  IPA_EDGE_REF (cs)->ipa_param_num = i;
  IPA_EDGE_REF (cs)->ipa_param_num = i;
}
}
 
 
/* Return the jump function (ipa_jump_func struct) for argument I of
/* Return the jump function (ipa_jump_func struct) for argument I of
   callsite CS.  */
   callsite CS.  */
struct ipa_jump_func *
struct ipa_jump_func *
ipa_callsite_param (struct cgraph_edge *cs, int i)
ipa_callsite_param (struct cgraph_edge *cs, int i)
{
{
  return &(IPA_EDGE_REF (cs)->ipa_param_map[i]);
  return &(IPA_EDGE_REF (cs)->ipa_param_map[i]);
}
}
 
 
/* return the callee (cgraph_node) of callsite CS.  */
/* return the callee (cgraph_node) of callsite CS.  */
struct cgraph_node *
struct cgraph_node *
ipa_callsite_callee (struct cgraph_edge *cs)
ipa_callsite_callee (struct cgraph_edge *cs)
{
{
  return cs->callee;
  return cs->callee;
}
}
 
 
/* Set field 'type' of jump function (ipa_jump_func struct) of argument I
/* Set field 'type' of jump function (ipa_jump_func struct) of argument I
   in callsite CS.  */
   in callsite CS.  */
static inline void
static inline void
ipa_callsite_param_set_type (struct cgraph_edge *cs, int i,
ipa_callsite_param_set_type (struct cgraph_edge *cs, int i,
                             enum jump_func_type type1)
                             enum jump_func_type type1)
{
{
  IPA_EDGE_REF (cs)->ipa_param_map[i].type = type1;
  IPA_EDGE_REF (cs)->ipa_param_map[i].type = type1;
}
}
 
 
/* Set FORMAL as 'info_type' field of jump function (ipa_jump_func struct)
/* Set FORMAL as 'info_type' field of jump function (ipa_jump_func struct)
   of argument I of callsite CS.  */
   of argument I of callsite CS.  */
static inline void
static inline void
ipa_callsite_param_set_info_type_formal (struct cgraph_edge *cs, int i,
ipa_callsite_param_set_info_type_formal (struct cgraph_edge *cs, int i,
                                         unsigned int formal)
                                         unsigned int formal)
{
{
  ipa_callsite_param (cs, i)->info_type.formal_id = formal;
  ipa_callsite_param (cs, i)->info_type.formal_id = formal;
}
}
 
 
/* Set int-valued INFO_TYPE1 as 'info_type' field of
/* Set int-valued INFO_TYPE1 as 'info_type' field of
   jump function (ipa_jump_func struct) of argument I of callsite CS.  */
   jump function (ipa_jump_func struct) of argument I of callsite CS.  */
static inline void
static inline void
ipa_callsite_param_set_info_type (struct cgraph_edge *cs, int i, tree info_type1)
ipa_callsite_param_set_info_type (struct cgraph_edge *cs, int i, tree info_type1)
{
{
  ipa_callsite_param (cs, i)->info_type.value = info_type1;
  ipa_callsite_param (cs, i)->info_type.value = info_type1;
}
}
 
 
/* Allocate space for callsite CS.  */
/* Allocate space for callsite CS.  */
static inline void
static inline void
ipa_callsite_param_map_create (struct cgraph_edge *cs)
ipa_callsite_param_map_create (struct cgraph_edge *cs)
{
{
  IPA_EDGE_REF (cs)->ipa_param_map =
  IPA_EDGE_REF (cs)->ipa_param_map =
    XCNEWVEC (struct ipa_jump_func, ipa_callsite_param_count (cs));
    XCNEWVEC (struct ipa_jump_func, ipa_callsite_param_count (cs));
}
}
 
 
/* Return the call expr tree related to callsite CS.  */
/* Return the call expr tree related to callsite CS.  */
static inline tree
static inline tree
ipa_callsite_tree (struct cgraph_edge *cs)
ipa_callsite_tree (struct cgraph_edge *cs)
{
{
  return cs->call_stmt;
  return cs->call_stmt;
}
}
 
 
/* Return the caller (cgraph_node) of CS.  */
/* Return the caller (cgraph_node) of CS.  */
static inline struct cgraph_node *
static inline struct cgraph_node *
ipa_callsite_caller (struct cgraph_edge *cs)
ipa_callsite_caller (struct cgraph_edge *cs)
{
{
  return cs->caller;
  return cs->caller;
}
}
 
 
/* Count number of arguments callsite CS has and store it in
/* Count number of arguments callsite CS has and store it in
   ipa_edge structure corresponding to this callsite.  */
   ipa_edge structure corresponding to this callsite.  */
void
void
ipa_callsite_compute_count (struct cgraph_edge *cs)
ipa_callsite_compute_count (struct cgraph_edge *cs)
{
{
  tree call_tree;
  tree call_tree;
  tree arg;
  tree arg;
  int arg_num;
  int arg_num;
 
 
  call_tree = get_call_expr_in (ipa_callsite_tree (cs));
  call_tree = get_call_expr_in (ipa_callsite_tree (cs));
  gcc_assert (TREE_CODE (call_tree) == CALL_EXPR);
  gcc_assert (TREE_CODE (call_tree) == CALL_EXPR);
  arg = TREE_OPERAND (call_tree, 1);
  arg = TREE_OPERAND (call_tree, 1);
  arg_num = 0;
  arg_num = 0;
  for (; arg != NULL_TREE; arg = TREE_CHAIN (arg))
  for (; arg != NULL_TREE; arg = TREE_CHAIN (arg))
    arg_num++;
    arg_num++;
  ipa_callsite_param_count_set (cs, arg_num);
  ipa_callsite_param_count_set (cs, arg_num);
}
}
 
 
/* Compute jump function for all arguments of callsite CS
/* Compute jump function for all arguments of callsite CS
   and insert the information in the ipa_param_map array
   and insert the information in the ipa_param_map array
   in the ipa_edge corresponding to this callsite. (Explanation
   in the ipa_edge corresponding to this callsite. (Explanation
   on jump functions is in ipa-prop.h).  */
   on jump functions is in ipa-prop.h).  */
void
void
ipa_callsite_compute_param (struct cgraph_edge *cs)
ipa_callsite_compute_param (struct cgraph_edge *cs)
{
{
  tree call_tree;
  tree call_tree;
  tree arg, cst_decl;
  tree arg, cst_decl;
  int arg_num;
  int arg_num;
  int i;
  int i;
  struct cgraph_node *mt;
  struct cgraph_node *mt;
 
 
  if (ipa_callsite_param_count (cs) == 0)
  if (ipa_callsite_param_count (cs) == 0)
    return;
    return;
  ipa_callsite_param_map_create (cs);
  ipa_callsite_param_map_create (cs);
  call_tree = get_call_expr_in (ipa_callsite_tree (cs));
  call_tree = get_call_expr_in (ipa_callsite_tree (cs));
  gcc_assert (TREE_CODE (call_tree) == CALL_EXPR);
  gcc_assert (TREE_CODE (call_tree) == CALL_EXPR);
  arg = TREE_OPERAND (call_tree, 1);
  arg = TREE_OPERAND (call_tree, 1);
  arg_num = 0;
  arg_num = 0;
 
 
  for (; arg != NULL_TREE; arg = TREE_CHAIN (arg))
  for (; arg != NULL_TREE; arg = TREE_CHAIN (arg))
    {
    {
      /* If the formal parameter was passed as argument, we store
      /* If the formal parameter was passed as argument, we store
         FORMAL_IPATYPE and its index in the caller as the jump function
         FORMAL_IPATYPE and its index in the caller as the jump function
         of this argument.  */
         of this argument.  */
      if (TREE_CODE (TREE_VALUE (arg)) == PARM_DECL)
      if (TREE_CODE (TREE_VALUE (arg)) == PARM_DECL)
        {
        {
          mt = ipa_callsite_caller (cs);
          mt = ipa_callsite_caller (cs);
          i = ipa_method_tree_map (mt, TREE_VALUE (arg));
          i = ipa_method_tree_map (mt, TREE_VALUE (arg));
          if (i < 0 || ipa_method_is_modified (mt, i))
          if (i < 0 || ipa_method_is_modified (mt, i))
            ipa_callsite_param_set_type (cs, arg_num, UNKNOWN_IPATYPE);
            ipa_callsite_param_set_type (cs, arg_num, UNKNOWN_IPATYPE);
          else
          else
            {
            {
              ipa_callsite_param_set_type (cs, arg_num, FORMAL_IPATYPE);
              ipa_callsite_param_set_type (cs, arg_num, FORMAL_IPATYPE);
              ipa_callsite_param_set_info_type_formal (cs, arg_num, i);
              ipa_callsite_param_set_info_type_formal (cs, arg_num, i);
            }
            }
        }
        }
      /* If a constant value was passed as argument,
      /* If a constant value was passed as argument,
         we store CONST_IPATYPE and its value as the jump function
         we store CONST_IPATYPE and its value as the jump function
         of this argument.  */
         of this argument.  */
      else if (TREE_CODE (TREE_VALUE (arg)) == INTEGER_CST
      else if (TREE_CODE (TREE_VALUE (arg)) == INTEGER_CST
               || TREE_CODE (TREE_VALUE (arg)) == REAL_CST)
               || TREE_CODE (TREE_VALUE (arg)) == REAL_CST)
        {
        {
          ipa_callsite_param_set_type (cs, arg_num, CONST_IPATYPE);
          ipa_callsite_param_set_type (cs, arg_num, CONST_IPATYPE);
          ipa_callsite_param_set_info_type (cs, arg_num,
          ipa_callsite_param_set_info_type (cs, arg_num,
                                            TREE_VALUE (arg));
                                            TREE_VALUE (arg));
        }
        }
      /* This is for the case of Fortran. If the address of a const_decl
      /* This is for the case of Fortran. If the address of a const_decl
         was passed as argument then we store
         was passed as argument then we store
         CONST_IPATYPE_REF/CONST_IPATYPE_REF and the constant
         CONST_IPATYPE_REF/CONST_IPATYPE_REF and the constant
         value as the jump function corresponding to this argument.  */
         value as the jump function corresponding to this argument.  */
      else if (TREE_CODE (TREE_VALUE (arg)) == ADDR_EXPR
      else if (TREE_CODE (TREE_VALUE (arg)) == ADDR_EXPR
               && TREE_CODE (TREE_OPERAND (TREE_VALUE (arg), 0)) ==
               && TREE_CODE (TREE_OPERAND (TREE_VALUE (arg), 0)) ==
               CONST_DECL)
               CONST_DECL)
        {
        {
          cst_decl = TREE_OPERAND (TREE_VALUE (arg), 0);
          cst_decl = TREE_OPERAND (TREE_VALUE (arg), 0);
          if (TREE_CODE (DECL_INITIAL (cst_decl)) == INTEGER_CST
          if (TREE_CODE (DECL_INITIAL (cst_decl)) == INTEGER_CST
              || TREE_CODE (DECL_INITIAL (cst_decl)) == REAL_CST)
              || TREE_CODE (DECL_INITIAL (cst_decl)) == REAL_CST)
            {
            {
              ipa_callsite_param_set_type (cs, arg_num,
              ipa_callsite_param_set_type (cs, arg_num,
                                           CONST_IPATYPE_REF);
                                           CONST_IPATYPE_REF);
              ipa_callsite_param_set_info_type (cs, arg_num,
              ipa_callsite_param_set_info_type (cs, arg_num,
                                                DECL_INITIAL (cst_decl));
                                                DECL_INITIAL (cst_decl));
            }
            }
        }
        }
      else
      else
        ipa_callsite_param_set_type (cs, arg_num, UNKNOWN_IPATYPE);
        ipa_callsite_param_set_type (cs, arg_num, UNKNOWN_IPATYPE);
      arg_num++;
      arg_num++;
    }
    }
}
}
 
 
/* Return type of jump function JF.  */
/* Return type of jump function JF.  */
enum jump_func_type
enum jump_func_type
get_type (struct ipa_jump_func *jf)
get_type (struct ipa_jump_func *jf)
{
{
  return jf->type;
  return jf->type;
}
}
 
 
/* Return info type of jump function JF.  */
/* Return info type of jump function JF.  */
union parameter_info *
union parameter_info *
ipa_jf_get_info_type (struct ipa_jump_func *jf)
ipa_jf_get_info_type (struct ipa_jump_func *jf)
{
{
  return &(jf->info_type);
  return &(jf->info_type);
}
}
 
 
/* Allocate and initialize ipa_node structure.
/* Allocate and initialize ipa_node structure.
   cgraph_node NODE points to the new allocated ipa_node.  */
   cgraph_node NODE points to the new allocated ipa_node.  */
void
void
ipa_node_create (struct cgraph_node *node)
ipa_node_create (struct cgraph_node *node)
{
{
  node->aux = xcalloc (1, sizeof (struct ipa_node));
  node->aux = xcalloc (1, sizeof (struct ipa_node));
}
}
 
 
/* Allocate and initialize ipa_node structure for all
/* Allocate and initialize ipa_node structure for all
   nodes in callgraph.  */
   nodes in callgraph.  */
void
void
ipa_nodes_create (void)
ipa_nodes_create (void)
{
{
  struct cgraph_node *node;
  struct cgraph_node *node;
 
 
  for (node = cgraph_nodes; node; node = node->next)
  for (node = cgraph_nodes; node; node = node->next)
    ipa_node_create (node);
    ipa_node_create (node);
}
}
 
 
/* Allocate and initialize ipa_edge structure.  */
/* Allocate and initialize ipa_edge structure.  */
void
void
ipa_edges_create (void)
ipa_edges_create (void)
{
{
  struct cgraph_node *node;
  struct cgraph_node *node;
  struct cgraph_edge *cs;
  struct cgraph_edge *cs;
 
 
  for (node = cgraph_nodes; node; node = node->next)
  for (node = cgraph_nodes; node; node = node->next)
    for (cs = node->callees; cs; cs = cs->next_callee)
    for (cs = node->callees; cs; cs = cs->next_callee)
      cs->aux = xcalloc (1, sizeof (struct ipa_edge));
      cs->aux = xcalloc (1, sizeof (struct ipa_edge));
}
}
 
 
/* Free ipa_node structure.  */
/* Free ipa_node structure.  */
void
void
ipa_nodes_free (void)
ipa_nodes_free (void)
{
{
  struct cgraph_node *node;
  struct cgraph_node *node;
 
 
  for (node = cgraph_nodes; node; node = node->next)
  for (node = cgraph_nodes; node; node = node->next)
    {
    {
      free (node->aux);
      free (node->aux);
      node->aux = NULL;
      node->aux = NULL;
    }
    }
}
}
 
 
/* Free ipa_edge structure.  */
/* Free ipa_edge structure.  */
void
void
ipa_edges_free (void)
ipa_edges_free (void)
{
{
  struct cgraph_node *node;
  struct cgraph_node *node;
  struct cgraph_edge *cs;
  struct cgraph_edge *cs;
 
 
  for (node = cgraph_nodes; node; node = node->next)
  for (node = cgraph_nodes; node; node = node->next)
    for (cs = node->callees; cs; cs = cs->next_callee)
    for (cs = node->callees; cs; cs = cs->next_callee)
      {
      {
        free (cs->aux);
        free (cs->aux);
        cs->aux = NULL;
        cs->aux = NULL;
      }
      }
}
}
 
 
/* Free ipa data structures of ipa_node and ipa_edge.  */
/* Free ipa data structures of ipa_node and ipa_edge.  */
void
void
ipa_free (void)
ipa_free (void)
{
{
  struct cgraph_node *node;
  struct cgraph_node *node;
  struct cgraph_edge *cs;
  struct cgraph_edge *cs;
 
 
  for (node = cgraph_nodes; node; node = node->next)
  for (node = cgraph_nodes; node; node = node->next)
    {
    {
      if (node->aux == NULL)
      if (node->aux == NULL)
        continue;
        continue;
      if (IPA_NODE_REF (node)->ipcp_cval)
      if (IPA_NODE_REF (node)->ipcp_cval)
        free (IPA_NODE_REF (node)->ipcp_cval);
        free (IPA_NODE_REF (node)->ipcp_cval);
      if (IPA_NODE_REF (node)->ipa_param_tree)
      if (IPA_NODE_REF (node)->ipa_param_tree)
        free (IPA_NODE_REF (node)->ipa_param_tree);
        free (IPA_NODE_REF (node)->ipa_param_tree);
      if (IPA_NODE_REF (node)->ipa_mod)
      if (IPA_NODE_REF (node)->ipa_mod)
        free (IPA_NODE_REF (node)->ipa_mod);
        free (IPA_NODE_REF (node)->ipa_mod);
      for (cs = node->callees; cs; cs = cs->next_callee)
      for (cs = node->callees; cs; cs = cs->next_callee)
        {
        {
          if (cs->aux)
          if (cs->aux)
            if (IPA_EDGE_REF (cs)->ipa_param_map)
            if (IPA_EDGE_REF (cs)->ipa_param_map)
              free (IPA_EDGE_REF (cs)->ipa_param_map);
              free (IPA_EDGE_REF (cs)->ipa_param_map);
        }
        }
    }
    }
}
}
 
 
/* Print ipa_tree_map data structures of all methods in the
/* Print ipa_tree_map data structures of all methods in the
   callgraph to F.  */
   callgraph to F.  */
void
void
ipa_method_tree_print (FILE * f)
ipa_method_tree_print (FILE * f)
{
{
  int i, count;
  int i, count;
  tree temp;
  tree temp;
  struct cgraph_node *node;
  struct cgraph_node *node;
 
 
  fprintf (f, "\nPARAM TREE MAP PRINT\n");
  fprintf (f, "\nPARAM TREE MAP PRINT\n");
  for (node = cgraph_nodes; node; node = node->next)
  for (node = cgraph_nodes; node; node = node->next)
    {
    {
      fprintf (f, "method  %s Trees :: \n", cgraph_node_name (node));
      fprintf (f, "method  %s Trees :: \n", cgraph_node_name (node));
      count = ipa_method_formal_count (node);
      count = ipa_method_formal_count (node);
      for (i = 0; i < count; i++)
      for (i = 0; i < count; i++)
        {
        {
          temp = ipa_method_get_tree (node, i);
          temp = ipa_method_get_tree (node, i);
          if (TREE_CODE (temp) == PARM_DECL)
          if (TREE_CODE (temp) == PARM_DECL)
            fprintf (f, "  param [%d] : %s\n", i,
            fprintf (f, "  param [%d] : %s\n", i,
                     (*lang_hooks.decl_printable_name) (temp, 2));
                     (*lang_hooks.decl_printable_name) (temp, 2));
        }
        }
 
 
    }
    }
}
}
 
 
/* Print ipa_modify data structures of all methods in the
/* Print ipa_modify data structures of all methods in the
   callgraph to F.  */
   callgraph to F.  */
void
void
ipa_method_modify_print (FILE * f)
ipa_method_modify_print (FILE * f)
{
{
  int i, count;
  int i, count;
  bool temp;
  bool temp;
  struct cgraph_node *node;
  struct cgraph_node *node;
 
 
  fprintf (f, "\nMODIFY PRINT\n");
  fprintf (f, "\nMODIFY PRINT\n");
  for (node = cgraph_nodes; node; node = node->next)
  for (node = cgraph_nodes; node; node = node->next)
    {
    {
      fprintf (f, "method  %s :: \n", cgraph_node_name (node));
      fprintf (f, "method  %s :: \n", cgraph_node_name (node));
      count = ipa_method_formal_count (node);
      count = ipa_method_formal_count (node);
      for (i = 0; i < count; i++)
      for (i = 0; i < count; i++)
        {
        {
          temp = ipa_method_is_modified (node, i);
          temp = ipa_method_is_modified (node, i);
          if (temp)
          if (temp)
            fprintf (f, " param [%d] true \n", i);
            fprintf (f, " param [%d] true \n", i);
          else
          else
            fprintf (f, " param [%d] false \n", i);
            fprintf (f, " param [%d] false \n", i);
        }
        }
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.