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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [varpool.c] - Diff between revs 816 and 826

Only display areas with differences | Details | Blame | View Log

Rev 816 Rev 826
/* Callgraph handling code.
/* Callgraph handling code.
   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010
   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
   Contributed by Jan Hubicka
   Contributed by Jan Hubicka
 
 
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 "tm.h"
#include "tm.h"
#include "tree.h"
#include "tree.h"
#include "cgraph.h"
#include "cgraph.h"
#include "langhooks.h"
#include "langhooks.h"
#include "diagnostic.h"
#include "diagnostic.h"
#include "hashtab.h"
#include "hashtab.h"
#include "ggc.h"
#include "ggc.h"
#include "timevar.h"
#include "timevar.h"
#include "debug.h"
#include "debug.h"
#include "target.h"
#include "target.h"
#include "output.h"
#include "output.h"
#include "gimple.h"
#include "gimple.h"
#include "tree-flow.h"
#include "tree-flow.h"
#include "flags.h"
#include "flags.h"
 
 
/*  This file contains basic routines manipulating variable pool.
/*  This file contains basic routines manipulating variable pool.
 
 
    Varpool acts as interface in between the front-end and middle-end
    Varpool acts as interface in between the front-end and middle-end
    and drives the decision process on what variables and when are
    and drives the decision process on what variables and when are
    going to be compiled.
    going to be compiled.
 
 
    The varpool nodes are allocated lazily for declarations
    The varpool nodes are allocated lazily for declarations
    either by frontend or at callgraph construction time.
    either by frontend or at callgraph construction time.
    All variables supposed to be output into final file needs to be
    All variables supposed to be output into final file needs to be
    explicitly marked by frontend via VARPOOL_FINALIZE_DECL function.  */
    explicitly marked by frontend via VARPOOL_FINALIZE_DECL function.  */
 
 
/* Hash table used to convert declarations into nodes.  */
/* Hash table used to convert declarations into nodes.  */
static GTY((param_is (struct varpool_node))) htab_t varpool_hash;
static GTY((param_is (struct varpool_node))) htab_t varpool_hash;
 
 
/* The linked list of cgraph varpool nodes.
/* The linked list of cgraph varpool nodes.
   Linked via node->next pointer.  */
   Linked via node->next pointer.  */
struct varpool_node *varpool_nodes;
struct varpool_node *varpool_nodes;
 
 
/* Queue of cgraph nodes scheduled to be lowered and output.
/* Queue of cgraph nodes scheduled to be lowered and output.
   The queue is maintained via mark_needed_node, linked via node->next_needed
   The queue is maintained via mark_needed_node, linked via node->next_needed
   pointer.
   pointer.
 
 
   LAST_NEEDED_NODE points to the end of queue, so it can be
   LAST_NEEDED_NODE points to the end of queue, so it can be
   maintained in forward order.  GTY is needed to make it friendly to
   maintained in forward order.  GTY is needed to make it friendly to
   PCH.
   PCH.
 
 
   During compilation we construct the queue of needed variables
   During compilation we construct the queue of needed variables
   twice: first time it is during cgraph construction, second time it is at the
   twice: first time it is during cgraph construction, second time it is at the
   end of compilation in VARPOOL_REMOVE_UNREFERENCED_DECLS so we can avoid
   end of compilation in VARPOOL_REMOVE_UNREFERENCED_DECLS so we can avoid
   optimized out variables being output.
   optimized out variables being output.
 
 
   Each variable is thus first analyzed and then later possibly output.
   Each variable is thus first analyzed and then later possibly output.
   FIRST_UNANALYZED_NODE points to first node in queue that was not analyzed
   FIRST_UNANALYZED_NODE points to first node in queue that was not analyzed
   yet and is moved via VARPOOL_ANALYZE_PENDING_DECLS.  */
   yet and is moved via VARPOOL_ANALYZE_PENDING_DECLS.  */
 
 
struct varpool_node *varpool_nodes_queue;
struct varpool_node *varpool_nodes_queue;
static GTY(()) struct varpool_node *varpool_last_needed_node;
static GTY(()) struct varpool_node *varpool_last_needed_node;
static GTY(()) struct varpool_node *varpool_first_unanalyzed_node;
static GTY(()) struct varpool_node *varpool_first_unanalyzed_node;
 
 
/* Lists all assembled variables to be sent to debugger output later on.  */
/* Lists all assembled variables to be sent to debugger output later on.  */
static GTY(()) struct varpool_node *varpool_assembled_nodes_queue;
static GTY(()) struct varpool_node *varpool_assembled_nodes_queue;
 
 
/* Return name of the node used in debug output.  */
/* Return name of the node used in debug output.  */
const char *
const char *
varpool_node_name (struct varpool_node *node)
varpool_node_name (struct varpool_node *node)
{
{
  return lang_hooks.decl_printable_name (node->decl, 2);
  return lang_hooks.decl_printable_name (node->decl, 2);
}
}
 
 
/* Returns a hash code for P.  */
/* Returns a hash code for P.  */
static hashval_t
static hashval_t
hash_varpool_node (const void *p)
hash_varpool_node (const void *p)
{
{
  const struct varpool_node *n = (const struct varpool_node *) p;
  const struct varpool_node *n = (const struct varpool_node *) p;
  return (hashval_t) DECL_UID (n->decl);
  return (hashval_t) DECL_UID (n->decl);
}
}
 
 
/* Returns nonzero if P1 and P2 are equal.  */
/* Returns nonzero if P1 and P2 are equal.  */
static int
static int
eq_varpool_node (const void *p1, const void *p2)
eq_varpool_node (const void *p1, const void *p2)
{
{
  const struct varpool_node *n1 =
  const struct varpool_node *n1 =
    (const struct varpool_node *) p1;
    (const struct varpool_node *) p1;
  const struct varpool_node *n2 =
  const struct varpool_node *n2 =
    (const struct varpool_node *) p2;
    (const struct varpool_node *) p2;
  return DECL_UID (n1->decl) == DECL_UID (n2->decl);
  return DECL_UID (n1->decl) == DECL_UID (n2->decl);
}
}
 
 
/* Return varpool node assigned to DECL.  Create new one when needed.  */
/* Return varpool node assigned to DECL.  Create new one when needed.  */
struct varpool_node *
struct varpool_node *
varpool_node (tree decl)
varpool_node (tree decl)
{
{
  struct varpool_node key, *node, **slot;
  struct varpool_node key, *node, **slot;
 
 
  gcc_assert (DECL_P (decl) && TREE_CODE (decl) != FUNCTION_DECL);
  gcc_assert (DECL_P (decl) && TREE_CODE (decl) != FUNCTION_DECL);
 
 
  if (!varpool_hash)
  if (!varpool_hash)
    varpool_hash = htab_create_ggc (10, hash_varpool_node,
    varpool_hash = htab_create_ggc (10, hash_varpool_node,
                                           eq_varpool_node, NULL);
                                           eq_varpool_node, NULL);
  key.decl = decl;
  key.decl = decl;
  slot = (struct varpool_node **)
  slot = (struct varpool_node **)
    htab_find_slot (varpool_hash, &key, INSERT);
    htab_find_slot (varpool_hash, &key, INSERT);
  if (*slot)
  if (*slot)
    return *slot;
    return *slot;
  node = GGC_CNEW (struct varpool_node);
  node = GGC_CNEW (struct varpool_node);
  node->decl = decl;
  node->decl = decl;
  node->order = cgraph_order++;
  node->order = cgraph_order++;
  node->next = varpool_nodes;
  node->next = varpool_nodes;
  varpool_nodes = node;
  varpool_nodes = node;
  *slot = node;
  *slot = node;
  return node;
  return node;
}
}
 
 
/* Dump given cgraph node.  */
/* Dump given cgraph node.  */
void
void
dump_varpool_node (FILE *f, struct varpool_node *node)
dump_varpool_node (FILE *f, struct varpool_node *node)
{
{
  fprintf (f, "%s:", varpool_node_name (node));
  fprintf (f, "%s:", varpool_node_name (node));
  fprintf (f, " availability:%s",
  fprintf (f, " availability:%s",
           cgraph_function_flags_ready
           cgraph_function_flags_ready
           ? cgraph_availability_names[cgraph_variable_initializer_availability (node)]
           ? cgraph_availability_names[cgraph_variable_initializer_availability (node)]
           : "not-ready");
           : "not-ready");
  if (DECL_INITIAL (node->decl))
  if (DECL_INITIAL (node->decl))
    fprintf (f, " initialized");
    fprintf (f, " initialized");
  if (node->needed)
  if (node->needed)
    fprintf (f, " needed");
    fprintf (f, " needed");
  if (node->analyzed)
  if (node->analyzed)
    fprintf (f, " analyzed");
    fprintf (f, " analyzed");
  if (node->finalized)
  if (node->finalized)
    fprintf (f, " finalized");
    fprintf (f, " finalized");
  if (node->output)
  if (node->output)
    fprintf (f, " output");
    fprintf (f, " output");
  if (node->externally_visible)
  if (node->externally_visible)
    fprintf (f, " externally_visible");
    fprintf (f, " externally_visible");
  fprintf (f, "\n");
  fprintf (f, "\n");
}
}
 
 
/* Dump the variable pool.  */
/* Dump the variable pool.  */
void
void
dump_varpool (FILE *f)
dump_varpool (FILE *f)
{
{
  struct varpool_node *node;
  struct varpool_node *node;
 
 
  fprintf (f, "variable pool:\n\n");
  fprintf (f, "variable pool:\n\n");
  for (node = varpool_nodes; node; node = node->next)
  for (node = varpool_nodes; node; node = node->next)
    dump_varpool_node (f, node);
    dump_varpool_node (f, node);
}
}
 
 
/* Dump the variable pool to stderr.  */
/* Dump the variable pool to stderr.  */
 
 
void
void
debug_varpool (void)
debug_varpool (void)
{
{
  dump_varpool (stderr);
  dump_varpool (stderr);
}
}
 
 
/* Given an assembler name, lookup node.  */
/* Given an assembler name, lookup node.  */
struct varpool_node *
struct varpool_node *
varpool_node_for_asm (tree asmname)
varpool_node_for_asm (tree asmname)
{
{
  struct varpool_node *node;
  struct varpool_node *node;
 
 
  for (node = varpool_nodes; node ; node = node->next)
  for (node = varpool_nodes; node ; node = node->next)
    if (decl_assembler_name_equal (node->decl, asmname))
    if (decl_assembler_name_equal (node->decl, asmname))
      return node;
      return node;
 
 
  return NULL;
  return NULL;
}
}
 
 
/* Helper function for finalization code - add node into lists so it will
/* Helper function for finalization code - add node into lists so it will
   be analyzed and compiled.  */
   be analyzed and compiled.  */
static void
static void
varpool_enqueue_needed_node (struct varpool_node *node)
varpool_enqueue_needed_node (struct varpool_node *node)
{
{
  if (varpool_last_needed_node)
  if (varpool_last_needed_node)
    varpool_last_needed_node->next_needed = node;
    varpool_last_needed_node->next_needed = node;
  varpool_last_needed_node = node;
  varpool_last_needed_node = node;
  node->next_needed = NULL;
  node->next_needed = NULL;
  if (!varpool_nodes_queue)
  if (!varpool_nodes_queue)
    varpool_nodes_queue = node;
    varpool_nodes_queue = node;
  if (!varpool_first_unanalyzed_node)
  if (!varpool_first_unanalyzed_node)
    varpool_first_unanalyzed_node = node;
    varpool_first_unanalyzed_node = node;
  notice_global_symbol (node->decl);
  notice_global_symbol (node->decl);
}
}
 
 
/* Notify finalize_compilation_unit that given node is reachable
/* Notify finalize_compilation_unit that given node is reachable
   or needed.  */
   or needed.  */
void
void
varpool_mark_needed_node (struct varpool_node *node)
varpool_mark_needed_node (struct varpool_node *node)
{
{
  if (node->alias && node->extra_name)
  if (node->alias && node->extra_name)
    node = node->extra_name;
    node = node->extra_name;
  if (!node->needed && node->finalized
  if (!node->needed && node->finalized
      && !TREE_ASM_WRITTEN (node->decl))
      && !TREE_ASM_WRITTEN (node->decl))
    varpool_enqueue_needed_node (node);
    varpool_enqueue_needed_node (node);
  node->needed = 1;
  node->needed = 1;
}
}
 
 
/* Reset the queue of needed nodes.  */
/* Reset the queue of needed nodes.  */
static void
static void
varpool_reset_queue (void)
varpool_reset_queue (void)
{
{
  varpool_last_needed_node = NULL;
  varpool_last_needed_node = NULL;
  varpool_nodes_queue = NULL;
  varpool_nodes_queue = NULL;
  varpool_first_unanalyzed_node = NULL;
  varpool_first_unanalyzed_node = NULL;
}
}
 
 
/* Determine if variable DECL is needed.  That is, visible to something
/* Determine if variable DECL is needed.  That is, visible to something
   either outside this translation unit, something magic in the system
   either outside this translation unit, something magic in the system
   configury */
   configury */
bool
bool
decide_is_variable_needed (struct varpool_node *node, tree decl)
decide_is_variable_needed (struct varpool_node *node, tree decl)
{
{
  /* If the user told us it is used, then it must be so.  */
  /* If the user told us it is used, then it must be so.  */
  if ((node->externally_visible && !DECL_COMDAT (decl))
  if ((node->externally_visible && !DECL_COMDAT (decl))
      || node->force_output)
      || node->force_output)
    return true;
    return true;
 
 
  /* ??? If the assembler name is set by hand, it is possible to assemble
  /* ??? If the assembler name is set by hand, it is possible to assemble
     the name later after finalizing the function and the fact is noticed
     the name later after finalizing the function and the fact is noticed
     in assemble_name then.  This is arguably a bug.  */
     in assemble_name then.  This is arguably a bug.  */
  if (DECL_ASSEMBLER_NAME_SET_P (decl)
  if (DECL_ASSEMBLER_NAME_SET_P (decl)
      && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
      && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
    return true;
    return true;
 
 
  /* Externally visible variables must be output.  The exception is
  /* Externally visible variables must be output.  The exception is
     COMDAT variables that must be output only when they are needed.  */
     COMDAT variables that must be output only when they are needed.  */
  if (TREE_PUBLIC (decl)
  if (TREE_PUBLIC (decl)
      && !flag_whole_program
      && !flag_whole_program
      && !flag_lto
      && !flag_lto
      && !flag_whopr
      && !flag_whopr
      && !DECL_COMDAT (decl)
      && !DECL_COMDAT (decl)
      && !DECL_EXTERNAL (decl))
      && !DECL_EXTERNAL (decl))
    return true;
    return true;
 
 
  /* When emulating tls, we actually see references to the control
  /* When emulating tls, we actually see references to the control
     variable, rather than the user-level variable.  */
     variable, rather than the user-level variable.  */
  if (!targetm.have_tls
  if (!targetm.have_tls
      && TREE_CODE (decl) == VAR_DECL
      && TREE_CODE (decl) == VAR_DECL
      && DECL_THREAD_LOCAL_P (decl))
      && DECL_THREAD_LOCAL_P (decl))
    {
    {
      tree control = emutls_decl (decl);
      tree control = emutls_decl (decl);
      if (decide_is_variable_needed (varpool_node (control), control))
      if (decide_is_variable_needed (varpool_node (control), control))
        return true;
        return true;
    }
    }
 
 
  /* When not reordering top level variables, we have to assume that
  /* When not reordering top level variables, we have to assume that
     we are going to keep everything.  */
     we are going to keep everything.  */
  if (flag_toplevel_reorder)
  if (flag_toplevel_reorder)
    return false;
    return false;
 
 
  /* We want to emit COMDAT variables only when absolutely necessary.  */
  /* We want to emit COMDAT variables only when absolutely necessary.  */
  if (DECL_COMDAT (decl))
  if (DECL_COMDAT (decl))
    return false;
    return false;
  return true;
  return true;
}
}
 
 
/* Mark DECL as finalized.  By finalizing the declaration, frontend instruct the
/* Mark DECL as finalized.  By finalizing the declaration, frontend instruct the
   middle end to output the variable to asm file, if needed or externally
   middle end to output the variable to asm file, if needed or externally
   visible.  */
   visible.  */
void
void
varpool_finalize_decl (tree decl)
varpool_finalize_decl (tree decl)
{
{
  struct varpool_node *node = varpool_node (decl);
  struct varpool_node *node = varpool_node (decl);
 
 
  /* FIXME: We don't really stream varpool datastructure and instead rebuild it
  /* FIXME: We don't really stream varpool datastructure and instead rebuild it
     by varpool_finalize_decl.  This is not quite correct since this way we can't
     by varpool_finalize_decl.  This is not quite correct since this way we can't
     attach any info to varpool.  Eventually we will want to stream varpool nodes
     attach any info to varpool.  Eventually we will want to stream varpool nodes
     and the flags.
     and the flags.
 
 
     For the moment just prevent analysis of varpool nodes to happen again, so
     For the moment just prevent analysis of varpool nodes to happen again, so
     we will re-try to compute "address_taken" flag of varpool that breaks
     we will re-try to compute "address_taken" flag of varpool that breaks
     in presence of clones.  */
     in presence of clones.  */
  if (in_lto_p)
  if (in_lto_p)
    node->analyzed = true;
    node->analyzed = true;
 
 
  /* The first declaration of a variable that comes through this function
  /* The first declaration of a variable that comes through this function
     decides whether it is global (in C, has external linkage)
     decides whether it is global (in C, has external linkage)
     or local (in C, has internal linkage).  So do nothing more
     or local (in C, has internal linkage).  So do nothing more
     if this function has already run.  */
     if this function has already run.  */
  if (node->finalized)
  if (node->finalized)
    {
    {
      if (cgraph_global_info_ready)
      if (cgraph_global_info_ready)
        varpool_assemble_pending_decls ();
        varpool_assemble_pending_decls ();
      return;
      return;
    }
    }
  if (node->needed)
  if (node->needed)
    varpool_enqueue_needed_node (node);
    varpool_enqueue_needed_node (node);
  node->finalized = true;
  node->finalized = true;
 
 
  if (decide_is_variable_needed (node, decl))
  if (decide_is_variable_needed (node, decl))
    varpool_mark_needed_node (node);
    varpool_mark_needed_node (node);
  /* Since we reclaim unreachable nodes at the end of every language
  /* Since we reclaim unreachable nodes at the end of every language
     level unit, we need to be conservative about possible entry points
     level unit, we need to be conservative about possible entry points
     there.  */
     there.  */
  else if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl))
  else if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl))
    varpool_mark_needed_node (node);
    varpool_mark_needed_node (node);
  if (cgraph_global_info_ready)
  if (cgraph_global_info_ready)
    varpool_assemble_pending_decls ();
    varpool_assemble_pending_decls ();
}
}
 
 
/* Return variable availability.  See cgraph.h for description of individual
/* Return variable availability.  See cgraph.h for description of individual
   return values.  */
   return values.  */
enum availability
enum availability
cgraph_variable_initializer_availability (struct varpool_node *node)
cgraph_variable_initializer_availability (struct varpool_node *node)
{
{
  gcc_assert (cgraph_function_flags_ready);
  gcc_assert (cgraph_function_flags_ready);
  if (!node->finalized)
  if (!node->finalized)
    return AVAIL_NOT_AVAILABLE;
    return AVAIL_NOT_AVAILABLE;
  if (!TREE_PUBLIC (node->decl))
  if (!TREE_PUBLIC (node->decl))
    return AVAIL_AVAILABLE;
    return AVAIL_AVAILABLE;
  /* If the variable can be overwritten, return OVERWRITABLE.  Takes
  /* If the variable can be overwritten, return OVERWRITABLE.  Takes
     care of at least two notable extensions - the COMDAT variables
     care of at least two notable extensions - the COMDAT variables
     used to share template instantiations in C++.  */
     used to share template instantiations in C++.  */
  if (!(*targetm.binds_local_p) (node->decl) && !DECL_COMDAT (node->decl))
  if (!(*targetm.binds_local_p) (node->decl) && !DECL_COMDAT (node->decl))
    return AVAIL_OVERWRITABLE;
    return AVAIL_OVERWRITABLE;
  return AVAIL_AVAILABLE;
  return AVAIL_AVAILABLE;
}
}
 
 
/* Walk the decls we marked as necessary and see if they reference new
/* Walk the decls we marked as necessary and see if they reference new
   variables or functions and add them into the worklists.  */
   variables or functions and add them into the worklists.  */
bool
bool
varpool_analyze_pending_decls (void)
varpool_analyze_pending_decls (void)
{
{
  bool changed = false;
  bool changed = false;
  timevar_push (TV_CGRAPH);
  timevar_push (TV_CGRAPH);
 
 
  while (varpool_first_unanalyzed_node)
  while (varpool_first_unanalyzed_node)
    {
    {
      tree decl = varpool_first_unanalyzed_node->decl;
      tree decl = varpool_first_unanalyzed_node->decl;
      bool analyzed = varpool_first_unanalyzed_node->analyzed;
      bool analyzed = varpool_first_unanalyzed_node->analyzed;
 
 
      varpool_first_unanalyzed_node->analyzed = true;
      varpool_first_unanalyzed_node->analyzed = true;
 
 
      varpool_first_unanalyzed_node = varpool_first_unanalyzed_node->next_needed;
      varpool_first_unanalyzed_node = varpool_first_unanalyzed_node->next_needed;
 
 
      /* When reading back varpool at LTO time, we re-construct the queue in order
      /* When reading back varpool at LTO time, we re-construct the queue in order
         to have "needed" list right by inserting all needed nodes into varpool.
         to have "needed" list right by inserting all needed nodes into varpool.
         We however don't want to re-analyze already analyzed nodes.  */
         We however don't want to re-analyze already analyzed nodes.  */
      if (!analyzed)
      if (!analyzed)
        {
        {
          gcc_assert (!in_lto_p);
          gcc_assert (!in_lto_p);
          /* Compute the alignment early so function body expanders are
          /* Compute the alignment early so function body expanders are
             already informed about increased alignment.  */
             already informed about increased alignment.  */
          align_variable (decl, 0);
          align_variable (decl, 0);
        }
        }
      if (DECL_INITIAL (decl))
      if (DECL_INITIAL (decl))
        record_references_in_initializer (decl, analyzed);
        record_references_in_initializer (decl, analyzed);
      changed = true;
      changed = true;
    }
    }
  timevar_pop (TV_CGRAPH);
  timevar_pop (TV_CGRAPH);
  return changed;
  return changed;
}
}
 
 
/* Output one variable, if necessary.  Return whether we output it.  */
/* Output one variable, if necessary.  Return whether we output it.  */
bool
bool
varpool_assemble_decl (struct varpool_node *node)
varpool_assemble_decl (struct varpool_node *node)
{
{
  tree decl = node->decl;
  tree decl = node->decl;
 
 
  if (!TREE_ASM_WRITTEN (decl)
  if (!TREE_ASM_WRITTEN (decl)
      && !node->alias
      && !node->alias
      && !DECL_EXTERNAL (decl)
      && !DECL_EXTERNAL (decl)
      && (TREE_CODE (decl) != VAR_DECL || !DECL_HAS_VALUE_EXPR_P (decl)))
      && (TREE_CODE (decl) != VAR_DECL || !DECL_HAS_VALUE_EXPR_P (decl)))
    {
    {
      assemble_variable (decl, 0, 1, 0);
      assemble_variable (decl, 0, 1, 0);
      if (TREE_ASM_WRITTEN (decl))
      if (TREE_ASM_WRITTEN (decl))
        {
        {
          struct varpool_node *alias;
          struct varpool_node *alias;
 
 
          node->next_needed = varpool_assembled_nodes_queue;
          node->next_needed = varpool_assembled_nodes_queue;
          varpool_assembled_nodes_queue = node;
          varpool_assembled_nodes_queue = node;
          node->finalized = 1;
          node->finalized = 1;
 
 
          /* Also emit any extra name aliases.  */
          /* Also emit any extra name aliases.  */
          for (alias = node->extra_name; alias; alias = alias->next)
          for (alias = node->extra_name; alias; alias = alias->next)
            {
            {
              /* Update linkage fields in case they've changed.  */
              /* Update linkage fields in case they've changed.  */
              DECL_WEAK (alias->decl) = DECL_WEAK (decl);
              DECL_WEAK (alias->decl) = DECL_WEAK (decl);
              TREE_PUBLIC (alias->decl) = TREE_PUBLIC (decl);
              TREE_PUBLIC (alias->decl) = TREE_PUBLIC (decl);
              DECL_VISIBILITY (alias->decl) = DECL_VISIBILITY (decl);
              DECL_VISIBILITY (alias->decl) = DECL_VISIBILITY (decl);
              assemble_alias (alias->decl, DECL_ASSEMBLER_NAME (decl));
              assemble_alias (alias->decl, DECL_ASSEMBLER_NAME (decl));
            }
            }
 
 
          return true;
          return true;
        }
        }
    }
    }
 
 
  return false;
  return false;
}
}
 
 
/* Optimization of function bodies might've rendered some variables as
/* Optimization of function bodies might've rendered some variables as
   unnecessary so we want to avoid these from being compiled.
   unnecessary so we want to avoid these from being compiled.
 
 
   This is done by pruning the queue and keeping only the variables that
   This is done by pruning the queue and keeping only the variables that
   really appear needed (ie they are either externally visible or referenced
   really appear needed (ie they are either externally visible or referenced
   by compiled function). Re-doing the reachability analysis on variables
   by compiled function). Re-doing the reachability analysis on variables
   brings back the remaining variables referenced by these.  */
   brings back the remaining variables referenced by these.  */
void
void
varpool_remove_unreferenced_decls (void)
varpool_remove_unreferenced_decls (void)
{
{
  struct varpool_node *next, *node = varpool_nodes_queue;
  struct varpool_node *next, *node = varpool_nodes_queue;
 
 
  varpool_reset_queue ();
  varpool_reset_queue ();
 
 
  if (errorcount || sorrycount)
  if (errorcount || sorrycount)
    return;
    return;
 
 
  while (node)
  while (node)
    {
    {
      tree decl = node->decl;
      tree decl = node->decl;
      next = node->next_needed;
      next = node->next_needed;
      node->needed = 0;
      node->needed = 0;
 
 
      if (node->finalized
      if (node->finalized
          && (decide_is_variable_needed (node, decl)
          && (decide_is_variable_needed (node, decl)
              /* ??? Cgraph does not yet rule the world with an iron hand,
              /* ??? Cgraph does not yet rule the world with an iron hand,
                 and does not control the emission of debug information.
                 and does not control the emission of debug information.
                 After a variable has its DECL_RTL set, we must assume that
                 After a variable has its DECL_RTL set, we must assume that
                 it may be referenced by the debug information, and we can
                 it may be referenced by the debug information, and we can
                 no longer elide it.  */
                 no longer elide it.  */
              || DECL_RTL_SET_P (decl)))
              || DECL_RTL_SET_P (decl)))
        varpool_mark_needed_node (node);
        varpool_mark_needed_node (node);
 
 
      node = next;
      node = next;
    }
    }
  /* Make sure we mark alias targets as used targets.  */
  /* Make sure we mark alias targets as used targets.  */
  finish_aliases_1 ();
  finish_aliases_1 ();
  varpool_analyze_pending_decls ();
  varpool_analyze_pending_decls ();
}
}
 
 
/* Output all variables enqueued to be assembled.  */
/* Output all variables enqueued to be assembled.  */
bool
bool
varpool_assemble_pending_decls (void)
varpool_assemble_pending_decls (void)
{
{
  bool changed = false;
  bool changed = false;
 
 
  if (errorcount || sorrycount)
  if (errorcount || sorrycount)
    return false;
    return false;
 
 
  /* EH might mark decls as needed during expansion.  This should be safe since
  /* EH might mark decls as needed during expansion.  This should be safe since
     we don't create references to new function, but it should not be used
     we don't create references to new function, but it should not be used
     elsewhere.  */
     elsewhere.  */
  varpool_analyze_pending_decls ();
  varpool_analyze_pending_decls ();
 
 
  while (varpool_nodes_queue)
  while (varpool_nodes_queue)
    {
    {
      struct varpool_node *node = varpool_nodes_queue;
      struct varpool_node *node = varpool_nodes_queue;
 
 
      varpool_nodes_queue = varpool_nodes_queue->next_needed;
      varpool_nodes_queue = varpool_nodes_queue->next_needed;
      if (varpool_assemble_decl (node))
      if (varpool_assemble_decl (node))
        changed = true;
        changed = true;
      else
      else
        node->next_needed = NULL;
        node->next_needed = NULL;
    }
    }
  /* varpool_nodes_queue is now empty, clear the pointer to the last element
  /* varpool_nodes_queue is now empty, clear the pointer to the last element
     in the queue.  */
     in the queue.  */
  varpool_last_needed_node = NULL;
  varpool_last_needed_node = NULL;
  return changed;
  return changed;
}
}
 
 
/* Remove all elements from the queue so we can re-use it for debug output.  */
/* Remove all elements from the queue so we can re-use it for debug output.  */
void
void
varpool_empty_needed_queue (void)
varpool_empty_needed_queue (void)
{
{
  /* EH might mark decls as needed during expansion.  This should be safe since
  /* EH might mark decls as needed during expansion.  This should be safe since
     we don't create references to new function, but it should not be used
     we don't create references to new function, but it should not be used
     elsewhere.  */
     elsewhere.  */
  varpool_analyze_pending_decls ();
  varpool_analyze_pending_decls ();
 
 
  while (varpool_nodes_queue)
  while (varpool_nodes_queue)
    {
    {
      struct varpool_node *node = varpool_nodes_queue;
      struct varpool_node *node = varpool_nodes_queue;
      varpool_nodes_queue = varpool_nodes_queue->next_needed;
      varpool_nodes_queue = varpool_nodes_queue->next_needed;
      node->next_needed = NULL;
      node->next_needed = NULL;
    }
    }
  /* varpool_nodes_queue is now empty, clear the pointer to the last element
  /* varpool_nodes_queue is now empty, clear the pointer to the last element
     in the queue.  */
     in the queue.  */
  varpool_last_needed_node = NULL;
  varpool_last_needed_node = NULL;
}
}
 
 
/* Create a new global variable of type TYPE.  */
/* Create a new global variable of type TYPE.  */
tree
tree
add_new_static_var (tree type)
add_new_static_var (tree type)
{
{
  tree new_decl;
  tree new_decl;
  struct varpool_node *new_node;
  struct varpool_node *new_node;
 
 
  new_decl = create_tmp_var (type, NULL);
  new_decl = create_tmp_var (type, NULL);
  DECL_NAME (new_decl) = create_tmp_var_name (NULL);
  DECL_NAME (new_decl) = create_tmp_var_name (NULL);
  TREE_READONLY (new_decl) = 0;
  TREE_READONLY (new_decl) = 0;
  TREE_STATIC (new_decl) = 1;
  TREE_STATIC (new_decl) = 1;
  TREE_USED (new_decl) = 1;
  TREE_USED (new_decl) = 1;
  DECL_CONTEXT (new_decl) = NULL_TREE;
  DECL_CONTEXT (new_decl) = NULL_TREE;
  DECL_ABSTRACT (new_decl) = 0;
  DECL_ABSTRACT (new_decl) = 0;
  lang_hooks.dup_lang_specific_decl (new_decl);
  lang_hooks.dup_lang_specific_decl (new_decl);
  create_var_ann (new_decl);
  create_var_ann (new_decl);
  new_node = varpool_node (new_decl);
  new_node = varpool_node (new_decl);
  varpool_mark_needed_node (new_node);
  varpool_mark_needed_node (new_node);
  add_referenced_var (new_decl);
  add_referenced_var (new_decl);
  varpool_finalize_decl (new_decl);
  varpool_finalize_decl (new_decl);
 
 
  return new_node->decl;
  return new_node->decl;
}
}
 
 
/* Attempt to mark ALIAS as an alias to DECL.  Return TRUE if successful.
/* Attempt to mark ALIAS as an alias to DECL.  Return TRUE if successful.
   Extra name aliases are output whenever DECL is output.  */
   Extra name aliases are output whenever DECL is output.  */
 
 
bool
bool
varpool_extra_name_alias (tree alias, tree decl)
varpool_extra_name_alias (tree alias, tree decl)
{
{
  struct varpool_node key, *alias_node, *decl_node, **slot;
  struct varpool_node key, *alias_node, *decl_node, **slot;
 
 
#ifndef ASM_OUTPUT_DEF
#ifndef ASM_OUTPUT_DEF
  /* If aliases aren't supported by the assembler, fail.  */
  /* If aliases aren't supported by the assembler, fail.  */
  return false;
  return false;
#endif
#endif
 
 
  gcc_assert (TREE_CODE (decl) == VAR_DECL);
  gcc_assert (TREE_CODE (decl) == VAR_DECL);
  gcc_assert (TREE_CODE (alias) == VAR_DECL);
  gcc_assert (TREE_CODE (alias) == VAR_DECL);
  /* Make sure the hash table has been created.  */
  /* Make sure the hash table has been created.  */
  decl_node = varpool_node (decl);
  decl_node = varpool_node (decl);
 
 
  key.decl = alias;
  key.decl = alias;
 
 
  slot = (struct varpool_node **) htab_find_slot (varpool_hash, &key, INSERT);
  slot = (struct varpool_node **) htab_find_slot (varpool_hash, &key, INSERT);
 
 
  /* If the varpool_node has been already created, fail.  */
  /* If the varpool_node has been already created, fail.  */
  if (*slot)
  if (*slot)
    return false;
    return false;
 
 
  alias_node = GGC_CNEW (struct varpool_node);
  alias_node = GGC_CNEW (struct varpool_node);
  alias_node->decl = alias;
  alias_node->decl = alias;
  alias_node->alias = 1;
  alias_node->alias = 1;
  alias_node->extra_name = decl_node;
  alias_node->extra_name = decl_node;
  alias_node->next = decl_node->extra_name;
  alias_node->next = decl_node->extra_name;
  decl_node->extra_name = alias_node;
  decl_node->extra_name = alias_node;
  *slot = alias_node;
  *slot = alias_node;
  return true;
  return true;
}
}
 
 
#include "gt-varpool.h"
#include "gt-varpool.h"
 
 

powered by: WebSVN 2.1.0

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