/* Generic partial redundancy elimination with lazy code motion support.
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
- Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008,
+ 2010, 2011 Free Software Foundation, Inc.
This file is part of GCC.
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
-Software Foundation; either version 2, or (at your option) any later
+Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
for more details.
You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING. If not, write to the Free
-Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA. */
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
/* These routines are meant to be used by various optimization
passes which can be modeled as lazy code motion problems.
#include "regs.h"
#include "hard-reg-set.h"
#include "flags.h"
-#include "real.h"
#include "insn-config.h"
#include "recog.h"
#include "basic-block.h"
#include "output.h"
#include "tm_p.h"
#include "function.h"
+#include "sbitmap.h"
/* We want target macros for the mode switching code to be able to refer
to instruction attribute values. */
/* Allocate a worklist array/queue. Entries are only added to the
list if they were not already on the list. So the size is
bounded by the number of basic blocks. */
- qin = qout = worklist = xmalloc (sizeof (basic_block) * n_basic_blocks);
+ qin = qout = worklist = XNEWVEC (basic_block, n_basic_blocks);
/* We want a maximal solution, so make an optimistic initialization of
ANTIN. */
}
qin = worklist;
- qend = &worklist[n_basic_blocks];
- qlen = n_basic_blocks;
+ qend = &worklist[n_basic_blocks - NUM_FIXED_BLOCKS];
+ qlen = n_basic_blocks - NUM_FIXED_BLOCKS;
/* Mark blocks which are predecessors of the exit block so that we
can easily identify them below. */
list if they were not already on the list. So the size is
bounded by the number of basic blocks. */
qin = qout = worklist
- = xmalloc (sizeof (basic_block) * (n_basic_blocks + 1));
+ = XNEWVEC (basic_block, n_basic_blocks);
/* Initialize a mapping from each edge to its index. */
for (i = 0; i < num_edges; i++)
}
/* Note that we do not use the last allocated element for our queue,
- as EXIT_BLOCK is never inserted into it. In fact the above allocation
- of n_basic_blocks + 1 elements is not necessary. */
+ as EXIT_BLOCK is never inserted into it. */
qin = worklist;
- qend = &worklist[n_basic_blocks];
- qlen = n_basic_blocks;
+ qend = &worklist[n_basic_blocks - NUM_FIXED_BLOCKS];
+ qlen = n_basic_blocks - NUM_FIXED_BLOCKS;
/* Iterate until the worklist is empty. */
while (qlen)
static void
compute_insert_delete (struct edge_list *edge_list, sbitmap *antloc,
sbitmap *later, sbitmap *laterin, sbitmap *insert,
- sbitmap *delete)
+ sbitmap *del)
{
int x;
basic_block bb;
FOR_EACH_BB (bb)
- sbitmap_difference (delete[bb->index], antloc[bb->index],
+ sbitmap_difference (del[bb->index], antloc[bb->index],
laterin[bb->index]);
for (x = 0; x < NUM_EDGES (edge_list); x++)
map the insert vector to what edge an expression should be inserted on. */
struct edge_list *
-pre_edge_lcm (FILE *file ATTRIBUTE_UNUSED, int n_exprs, sbitmap *transp,
+pre_edge_lcm (int n_exprs, sbitmap *transp,
sbitmap *avloc, sbitmap *antloc, sbitmap *kill,
- sbitmap **insert, sbitmap **delete)
+ sbitmap **insert, sbitmap **del)
{
sbitmap *antin, *antout, *earliest;
sbitmap *avin, *avout;
num_edges = NUM_EDGES (edge_list);
#ifdef LCM_DEBUG_INFO
- if (file)
+ if (dump_file)
{
- fprintf (file, "Edge List:\n");
- verify_edge_list (file, edge_list);
- print_edge_list (file, edge_list);
- dump_sbitmap_vector (file, "transp", "", transp, last_basic_block);
- dump_sbitmap_vector (file, "antloc", "", antloc, last_basic_block);
- dump_sbitmap_vector (file, "avloc", "", avloc, last_basic_block);
- dump_sbitmap_vector (file, "kill", "", kill, last_basic_block);
+ fprintf (dump_file, "Edge List:\n");
+ verify_edge_list (dump_file, edge_list);
+ print_edge_list (dump_file, edge_list);
+ dump_sbitmap_vector (dump_file, "transp", "", transp, last_basic_block);
+ dump_sbitmap_vector (dump_file, "antloc", "", antloc, last_basic_block);
+ dump_sbitmap_vector (dump_file, "avloc", "", avloc, last_basic_block);
+ dump_sbitmap_vector (dump_file, "kill", "", kill, last_basic_block);
}
#endif
compute_antinout_edge (antloc, transp, antin, antout);
#ifdef LCM_DEBUG_INFO
- if (file)
+ if (dump_file)
{
- dump_sbitmap_vector (file, "antin", "", antin, last_basic_block);
- dump_sbitmap_vector (file, "antout", "", antout, last_basic_block);
+ dump_sbitmap_vector (dump_file, "antin", "", antin, last_basic_block);
+ dump_sbitmap_vector (dump_file, "antout", "", antout, last_basic_block);
}
#endif
compute_earliest (edge_list, n_exprs, antin, antout, avout, kill, earliest);
#ifdef LCM_DEBUG_INFO
- if (file)
- dump_sbitmap_vector (file, "earliest", "", earliest, num_edges);
+ if (dump_file)
+ dump_sbitmap_vector (dump_file, "earliest", "", earliest, num_edges);
#endif
sbitmap_vector_free (antout);
compute_laterin (edge_list, earliest, antloc, later, laterin);
#ifdef LCM_DEBUG_INFO
- if (file)
+ if (dump_file)
{
- dump_sbitmap_vector (file, "laterin", "", laterin, last_basic_block + 1);
- dump_sbitmap_vector (file, "later", "", later, num_edges);
+ dump_sbitmap_vector (dump_file, "laterin", "", laterin, last_basic_block + 1);
+ dump_sbitmap_vector (dump_file, "later", "", later, num_edges);
}
#endif
sbitmap_vector_free (earliest);
*insert = sbitmap_vector_alloc (num_edges, n_exprs);
- *delete = sbitmap_vector_alloc (last_basic_block, n_exprs);
- compute_insert_delete (edge_list, antloc, later, laterin, *insert, *delete);
+ *del = sbitmap_vector_alloc (last_basic_block, n_exprs);
+ sbitmap_vector_zero (*insert, num_edges);
+ sbitmap_vector_zero (*del, last_basic_block);
+ compute_insert_delete (edge_list, antloc, later, laterin, *insert, *del);
sbitmap_vector_free (laterin);
sbitmap_vector_free (later);
#ifdef LCM_DEBUG_INFO
- if (file)
+ if (dump_file)
{
- dump_sbitmap_vector (file, "pre_insert_map", "", *insert, num_edges);
- dump_sbitmap_vector (file, "pre_delete_map", "", *delete,
+ dump_sbitmap_vector (dump_file, "pre_insert_map", "", *insert, num_edges);
+ dump_sbitmap_vector (dump_file, "pre_delete_map", "", *del,
last_basic_block);
}
#endif
/* Allocate a worklist array/queue. Entries are only added to the
list if they were not already on the list. So the size is
bounded by the number of basic blocks. */
- qin = qout = worklist = xmalloc (sizeof (basic_block) * n_basic_blocks);
+ qin = qout = worklist =
+ XNEWVEC (basic_block, n_basic_blocks - NUM_FIXED_BLOCKS);
/* We want a maximal solution. */
sbitmap_vector_ones (avout, last_basic_block);
}
qin = worklist;
- qend = &worklist[n_basic_blocks];
- qlen = n_basic_blocks;
+ qend = &worklist[n_basic_blocks - NUM_FIXED_BLOCKS];
+ qlen = n_basic_blocks - NUM_FIXED_BLOCKS;
/* Mark blocks which are successors of the entry block so that we
can easily identify them below. */
/* Allocate a worklist array/queue. Entries are only added to the
list if they were not already on the list. So the size is
bounded by the number of basic blocks. */
- tos = worklist = xmalloc (sizeof (basic_block) * (n_basic_blocks + 1));
+ tos = worklist = XNEWVEC (basic_block, n_basic_blocks + 1);
/* Initialize NEARER for each edge and build a mapping from an edge to
its index. */
static void
compute_rev_insert_delete (struct edge_list *edge_list, sbitmap *st_avloc,
sbitmap *nearer, sbitmap *nearerout,
- sbitmap *insert, sbitmap *delete)
+ sbitmap *insert, sbitmap *del)
{
int x;
basic_block bb;
FOR_EACH_BB (bb)
- sbitmap_difference (delete[bb->index], st_avloc[bb->index],
+ sbitmap_difference (del[bb->index], st_avloc[bb->index],
nearerout[bb->index]);
for (x = 0; x < NUM_EDGES (edge_list); x++)
an expression should be inserted on. */
struct edge_list *
-pre_edge_rev_lcm (FILE *file ATTRIBUTE_UNUSED, int n_exprs, sbitmap *transp,
+pre_edge_rev_lcm (int n_exprs, sbitmap *transp,
sbitmap *st_avloc, sbitmap *st_antloc, sbitmap *kill,
- sbitmap **insert, sbitmap **delete)
+ sbitmap **insert, sbitmap **del)
{
sbitmap *st_antin, *st_antout;
sbitmap *st_avout, *st_avin, *farthest;
compute_available (st_avloc, kill, st_avout, st_avin);
#ifdef LCM_DEBUG_INFO
- if (file)
+ if (dump_file)
{
- fprintf (file, "Edge List:\n");
- verify_edge_list (file, edge_list);
- print_edge_list (file, edge_list);
- dump_sbitmap_vector (file, "transp", "", transp, last_basic_block);
- dump_sbitmap_vector (file, "st_avloc", "", st_avloc, last_basic_block);
- dump_sbitmap_vector (file, "st_antloc", "", st_antloc, last_basic_block);
- dump_sbitmap_vector (file, "st_antin", "", st_antin, last_basic_block);
- dump_sbitmap_vector (file, "st_antout", "", st_antout, last_basic_block);
- dump_sbitmap_vector (file, "st_kill", "", kill, last_basic_block);
+ fprintf (dump_file, "Edge List:\n");
+ verify_edge_list (dump_file, edge_list);
+ print_edge_list (dump_file, edge_list);
+ dump_sbitmap_vector (dump_file, "transp", "", transp, last_basic_block);
+ dump_sbitmap_vector (dump_file, "st_avloc", "", st_avloc, last_basic_block);
+ dump_sbitmap_vector (dump_file, "st_antloc", "", st_antloc, last_basic_block);
+ dump_sbitmap_vector (dump_file, "st_antin", "", st_antin, last_basic_block);
+ dump_sbitmap_vector (dump_file, "st_antout", "", st_antout, last_basic_block);
+ dump_sbitmap_vector (dump_file, "st_kill", "", kill, last_basic_block);
}
#endif
#ifdef LCM_DEBUG_INFO
- if (file)
+ if (dump_file)
{
- dump_sbitmap_vector (file, "st_avout", "", st_avout, last_basic_block);
- dump_sbitmap_vector (file, "st_avin", "", st_avin, last_basic_block);
+ dump_sbitmap_vector (dump_file, "st_avout", "", st_avout, last_basic_block);
+ dump_sbitmap_vector (dump_file, "st_avin", "", st_avin, last_basic_block);
}
#endif
kill, farthest);
#ifdef LCM_DEBUG_INFO
- if (file)
- dump_sbitmap_vector (file, "farthest", "", farthest, num_edges);
+ if (dump_file)
+ dump_sbitmap_vector (dump_file, "farthest", "", farthest, num_edges);
#endif
sbitmap_vector_free (st_antin);
compute_nearerout (edge_list, farthest, st_avloc, nearer, nearerout);
#ifdef LCM_DEBUG_INFO
- if (file)
+ if (dump_file)
{
- dump_sbitmap_vector (file, "nearerout", "", nearerout,
+ dump_sbitmap_vector (dump_file, "nearerout", "", nearerout,
last_basic_block + 1);
- dump_sbitmap_vector (file, "nearer", "", nearer, num_edges);
+ dump_sbitmap_vector (dump_file, "nearer", "", nearer, num_edges);
}
#endif
sbitmap_vector_free (farthest);
*insert = sbitmap_vector_alloc (num_edges, n_exprs);
- *delete = sbitmap_vector_alloc (last_basic_block, n_exprs);
+ *del = sbitmap_vector_alloc (last_basic_block, n_exprs);
compute_rev_insert_delete (edge_list, st_avloc, nearer, nearerout,
- *insert, *delete);
+ *insert, *del);
sbitmap_vector_free (nearerout);
sbitmap_vector_free (nearer);
#ifdef LCM_DEBUG_INFO
- if (file)
+ if (dump_file)
{
- dump_sbitmap_vector (file, "pre_insert_map", "", *insert, num_edges);
- dump_sbitmap_vector (file, "pre_delete_map", "", *delete,
+ dump_sbitmap_vector (dump_file, "pre_insert_map", "", *insert, num_edges);
+ dump_sbitmap_vector (dump_file, "pre_delete_map", "", *del,
last_basic_block);
}
#endif