[PATCH 1/2] add unique_ptr header

2017-07-31 Thread tbsaunde+gcc
From: Trevor Saunders 

For most of the history of this see 
https://sourceware.org/ml/gdb-patches/2016-10/msg00223.html
The changes are mostly s/gdb/gtl/g

include/ChangeLog:

2017-07-29  Trevor Saunders  

* unique-ptr.h: New file.
---
 include/unique-ptr.h | 386 +++
 1 file changed, 386 insertions(+)
 create mode 100644 include/unique-ptr.h

diff --git a/include/unique-ptr.h b/include/unique-ptr.h
new file mode 100644
index 000..7903a5abefe
--- /dev/null
+++ b/include/unique-ptr.h
@@ -0,0 +1,386 @@
+/* gtl::unique_ptr, a simple std::unique_ptr replacement for C++03.
+
+   Copyright (C) 2007-2016 Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   This program 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 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see .  */
+
+/* gtl::unique_ptr defines a C++ owning smart pointer that exposes a
+   subset of the std::unique_ptr API.
+
+   In fact, when compiled with a C++11 compiler, gtl::unique_ptr
+   actually _is_ std::unique_ptr.  When compiled with a C++03 compiler
+   OTOH, it's an hand coded std::unique_ptr emulation that assumes
+   code is correct and doesn't try to be too smart.
+
+   This supports custom deleters, but not _stateful_ deleters, so you
+   can't use those in C++11 mode either.  Only the managed pointer is
+   stored in the smart pointer.  That could be changed; it simply
+   wasn't found necessary.
+
+   At the end of the file you'll find a gtl::unique_ptr partial
+   specialization that uses a custom (stateless) deleter:
+   gtl::unique_xmalloc_ptr.  That is used to manage pointers to
+   objects allocated with xmalloc.
+
+   The C++03 version was originally based on GCC 7.0's std::auto_ptr
+   and then heavily customized to behave more like C++11's
+   std::unique_ptr, but at this point, it no longer shares much at all
+   with the original file.  But, that's the history and the reason for
+   the copyright's starting year.
+
+   The C++03 version lets you shoot yourself in the foot, since
+   similarly to std::auto_ptr, the copy constructor and assignment
+   operators actually move.  Also, in the name of simplicity, no
+   effort is spent on using SFINAE to prevent invalid conversions,
+   etc.  This is not really a problem, because the goal here is to
+   allow code that would be correct using std::unique_ptr to be
+   equally correct in C++03 mode, and, just as efficient.  If client
+   code compiles correctly with a C++11 (or newer) compiler, we know
+   we're not doing anything invalid by mistake.
+
+   Usage notes:
+
+   - Putting gtl::unique_ptr in standard containers is not supported,
+ since C++03 containers are not move-aware (and our emulation
+ relies on copy actually moving).
+
+   - Since there's no nullptr in C++03, gtl::unique_ptr allows
+ implicit initialization and assignment from NULL instead.
+
+   - To check whether there's an associated managed object, all these
+ work as expected:
+
+  if (ptr)
+  if (!ptr)
+  if (ptr != NULL)
+  if (ptr == NULL)
+  if (NULL != ptr)
+  if (NULL == ptr)
+*/
+
+#ifndef GTL_UNIQUE_PTR_H
+#define GTL_UNIQUE_PTR_H 1
+
+#include 
+
+namespace gtl
+{
+
+#if __cplusplus >= 201103
+
+/* In C++11 mode, all we need is import the standard
+   std::unique_ptr.  */
+template using unique_ptr = std::unique_ptr;
+
+/* Pull in move as well.  */
+using std::move;
+
+#else /* C++11 */
+
+/* Default destruction policy used by gtl::unique_ptr when no deleter
+   is specified.  Uses delete.  */
+
+template
+struct default_delete
+{
+  void operator () (T *ptr) const { delete ptr; }
+};
+
+/* Specialization for arrays.  Uses delete[].  */
+
+template
+struct default_delete
+{
+  void operator () (T *ptr) const { delete [] ptr; }
+};
+
+namespace detail
+{
+/* Type used to support implicit construction from NULL:
+
+ gtl::unique_ptr func ()
+ {
+ return NULL;
+ }
+
+   and assignment from NULL:
+
+ gtl::unique_ptr ptr ();
+ ...
+ ptr = NULL;
+
+  It is intentionally not defined anywhere.  */
+struct nullptr_t;
+
+/* Base class of our unique_ptr emulation.  Contains code common to
+   both unique_ptr and unique_ptr.  */
+
+template
+class unique_ptr_base
+{
+public:
+  typedef T *pointer;
+  typedef T element_type;
+  typedef D deleter_type;
+
+  /* 

[PATCH 2/2] use unique_ptr some

2017-07-31 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-31  Trevor Saunders  

* cse.c (find_comparison_args): Make visited a unique_ptr.
* lto-streamer-out.c (write_global_references): Make data a
unique_ptr.
* tree-cfg.c (move_sese_region_to_fn): Make several variables
unique_ptrs.
---
 gcc/cse.c  |  7 +++
 gcc/lto-streamer-out.c |  6 +++---
 gcc/tree-cfg.c | 38 +-
 3 files changed, 19 insertions(+), 32 deletions(-)

diff --git a/gcc/cse.c b/gcc/cse.c
index 6a968d19788..45da9b2da9d 100644
--- a/gcc/cse.c
+++ b/gcc/cse.c
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "unique-ptr.h"
 #include "backend.h"
 #include "target.h"
 #include "rtl.h"
@@ -2887,7 +2888,7 @@ find_comparison_args (enum rtx_code code, rtx *parg1, rtx 
*parg2,
  machine_mode *pmode1, machine_mode *pmode2)
 {
   rtx arg1, arg2;
-  hash_set *visited = NULL;
+  gtl::unique_ptr visited;
   /* Set nonzero when we find something of interest.  */
   rtx x = NULL;
 
@@ -2904,7 +2905,7 @@ find_comparison_args (enum rtx_code code, rtx *parg1, rtx 
*parg2,
   if (x)
{
  if (!visited)
-   visited = new hash_set;
+   visited.reset (new hash_set);
  visited->add (x);
  x = 0;
}
@@ -3067,8 +3068,6 @@ find_comparison_args (enum rtx_code code, rtx *parg1, rtx 
*parg2,
   *pmode1 = GET_MODE (arg1), *pmode2 = GET_MODE (arg2);
   *parg1 = fold_rtx (arg1, 0), *parg2 = fold_rtx (arg2, 0);
 
-  if (visited)
-delete visited;
   return code;
 }
 
diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c
index 41fba318cb5..61576c30266 100644
--- a/gcc/lto-streamer-out.c
+++ b/gcc/lto-streamer-out.c
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "unique-ptr.h"
 #include "backend.h"
 #include "target.h"
 #include "rtl.h"
@@ -2434,7 +2435,7 @@ write_global_references (struct output_block *ob,
   const uint32_t size = lto_tree_ref_encoder_size (encoder);
 
   /* Write size and slot indexes as 32-bit unsigned numbers. */
-  uint32_t *data = XNEWVEC (uint32_t, size + 1);
+  gtl::unique_ptr data (new uint32_t[size + 1]);
   data[0] = size;
 
   for (index = 0; index < size; index++)
@@ -2447,8 +2448,7 @@ write_global_references (struct output_block *ob,
   data[index + 1] = slot_num;
 }
 
-  lto_write_data (data, sizeof (int32_t) * (size + 1));
-  free (data);
+  lto_write_data (data.get (), sizeof (int32_t) * (size + 1));
 }
 
 
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 733c92fcdd0..604f799926c 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "unique-ptr.h"
 #include "backend.h"
 #include "target.h"
 #include "rtl.h"
@@ -7252,10 +7253,8 @@ move_sese_region_to_fn (struct function *dest_cfun, 
basic_block entry_bb,
 {
   vec bbs, dom_bbs;
   basic_block dom_entry = get_immediate_dominator (CDI_DOMINATORS, entry_bb);
-  basic_block after, bb, *entry_pred, *exit_succ, abb;
+  basic_block after, bb, abb;
   struct function *saved_cfun = cfun;
-  int *entry_flag, *exit_flag;
-  profile_probability *entry_prob, *exit_prob;
   unsigned i, num_entry_edges, num_exit_edges, num_nodes;
   edge e;
   edge_iterator ei;
@@ -7291,9 +7290,10 @@ move_sese_region_to_fn (struct function *dest_cfun, 
basic_block entry_bb,
  EXIT_BB so that we can re-attach them to the new basic block that
  will replace the region.  */
   num_entry_edges = EDGE_COUNT (entry_bb->preds);
-  entry_pred = XNEWVEC (basic_block, num_entry_edges);
-  entry_flag = XNEWVEC (int, num_entry_edges);
-  entry_prob = XNEWVEC (profile_probability, num_entry_edges);
+  gtl::unique_ptr entry_pred (new basic_block[num_entry_edges]);
+  gtl::unique_ptr entry_flag (new int[num_entry_edges]);
+  gtl::unique_ptr entry_prob
+(new profile_probability[num_entry_edges]);
   i = 0;
   for (ei = ei_start (entry_bb->preds); (e = ei_safe_edge (ei)) != NULL;)
 {
@@ -7303,12 +7303,15 @@ move_sese_region_to_fn (struct function *dest_cfun, 
basic_block entry_bb,
   remove_edge (e);
 }
 
+  gtl::unique_ptr exit_succ;
+  gtl::unique_ptr exit_flag;
+  gtl::unique_ptr exit_prob;
   if (exit_bb)
 {
   num_exit_edges = EDGE_COUNT (exit_bb->succs);
-  exit_succ = XNEWVEC (basic_block, num_exit_edges);
-  exit_flag = XNEWVEC (int, num_exit_edges);
-  exit_prob = XNEWVEC (profile_probability, num_exit_edges);
+  exit_succ.reset (new basic_block[num_exit_edges]);
+  exit_flag.reset (new 

[PATCH 0/2] add unique_ptr class

2017-07-31 Thread tbsaunde+gcc
From: Trevor Saunders 

Hi,

I've been saying I'd do this for a long time, but I'm finally getting to
importing the C++98 compatable unique_ptr class Pedro wrote for gdb a while
back.  I believe the gtl namespace also comes from Pedro, but GNU template
library seems as reasonable as any other name I can come up with.  I'm not sure
at the moment what outside of gcc may want to use this, but putting it include/
at least allows us to use it in libcpp which may be useful.  I didn't include
too much usage in this series, but I believe other people have wanted this too,
so I'm reasonably confident it will get a fair amount of usage.

patches individually bootstrapped + regtested on ppc64-linux-gnu, ok?

Trev




[PATCH 18/19] use c++ for gimple_build_debug_bind{,_source}

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* gimple.c (gimple_build_debug_bind_stat): Remove _stat from name.
(gimple_build_debug_bind_source_stat): Likewise.
* gimple.h (gimple_build_debug_bind): Remove macro.
(gimple_build_debug_bind_source): Likewise.
---
 gcc/gimple.c | 4 ++--
 gcc/gimple.h | 8 ++--
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/gcc/gimple.c b/gcc/gimple.c
index 13a68284879..3a32b530cce 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -796,7 +796,7 @@ gimple_build_eh_dispatch (int region)
VAR is bound to VALUE; block and location are taken from STMT.  */
 
 gdebug *
-gimple_build_debug_bind_stat (tree var, tree value, gimple *stmt MEM_STAT_DECL)
+gimple_build_debug_bind (tree var, tree value, gimple *stmt MEM_STAT_DECL)
 {
   gdebug *p
 = as_a  (gimple_build_with_ops_stat (GIMPLE_DEBUG,
@@ -816,7 +816,7 @@ gimple_build_debug_bind_stat (tree var, tree value, gimple 
*stmt MEM_STAT_DECL)
VAR is bound to VALUE; block and location are taken from STMT.  */
 
 gdebug *
-gimple_build_debug_source_bind_stat (tree var, tree value,
+gimple_build_debug_source_bind (tree var, tree value,
 gimple *stmt MEM_STAT_DECL)
 {
   gdebug *p
diff --git a/gcc/gimple.h b/gcc/gimple.h
index d9945648215..6213c49b91f 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -1453,12 +1453,8 @@ gresx *gimple_build_resx (int);
 gswitch *gimple_build_switch_nlabels (unsigned, tree, tree);
 gswitch *gimple_build_switch (tree, tree, vec );
 geh_dispatch *gimple_build_eh_dispatch (int);
-gdebug *gimple_build_debug_bind_stat (tree, tree, gimple * MEM_STAT_DECL);
-#define gimple_build_debug_bind(var,val,stmt)  \
-  gimple_build_debug_bind_stat ((var), (val), (stmt) MEM_STAT_INFO)
-gdebug *gimple_build_debug_source_bind_stat (tree, tree, gimple * 
MEM_STAT_DECL);
-#define gimple_build_debug_source_bind(var,val,stmt)   \
-  gimple_build_debug_source_bind_stat ((var), (val), (stmt) MEM_STAT_INFO)
+gdebug *gimple_build_debug_bind (tree, tree, gimple * CXX_MEM_STAT_INFO);
+gdebug *gimple_build_debug_source_bind (tree, tree, gimple * 
CXX_MEM_STAT_INFO);
 gomp_critical *gimple_build_omp_critical (gimple_seq, tree, tree);
 gomp_for *gimple_build_omp_for (gimple_seq, int, tree, size_t, gimple_seq);
 gomp_parallel *gimple_build_omp_parallel (gimple_seq, tree, tree, tree);
-- 
2.11.0



[PATCH 19/19] use c++ for fold_buildN_loc

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* fold-const.c (fold_build1_stat_loc): Remove _stat from name.
(fold_build2_stat_loc): Likewise.
(fold_build3_stat_loc): Likewise.
* fold-const.h (fold_build1, fold_build2, fold_build3): Adjust.
(fold_build1_loc): Remove macro.
(fold_build2_loc): Likewise.
(fold_build3_loc): Likewise.
---
 gcc/fold-const.c |  8 
 gcc/fold-const.h | 24 +---
 2 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 976924f34d7..d4e03b96937 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -12205,8 +12205,8 @@ debug_fold_checksum (const_tree t)
expression with code CODE of type TYPE with an operand OP0.  */
 
 tree
-fold_build1_stat_loc (location_t loc,
- enum tree_code code, tree type, tree op0 MEM_STAT_DECL)
+fold_build1_loc (location_t loc,
+enum tree_code code, tree type, tree op0 MEM_STAT_DECL)
 {
   tree tem;
 #ifdef ENABLE_FOLD_CHECKING
@@ -12242,7 +12242,7 @@ fold_build1_stat_loc (location_t loc,
OP0 and OP1.  */
 
 tree
-fold_build2_stat_loc (location_t loc,
+fold_build2_loc (location_t loc,
  enum tree_code code, tree type, tree op0, tree op1
  MEM_STAT_DECL)
 {
@@ -12295,7 +12295,7 @@ fold_build2_stat_loc (location_t loc,
type TYPE with operands OP0, OP1, and OP2.  */
 
 tree
-fold_build3_stat_loc (location_t loc, enum tree_code code, tree type,
+fold_build3_loc (location_t loc, enum tree_code code, tree type,
  tree op0, tree op1, tree op2 MEM_STAT_DECL)
 {
   tree tem;
diff --git a/gcc/fold-const.h b/gcc/fold-const.h
index 780e5c781b7..8380d420ddb 100644
--- a/gcc/fold-const.h
+++ b/gcc/fold-const.h
@@ -49,23 +49,17 @@ extern tree fold_binary_loc (location_t, enum tree_code, 
tree, tree, tree);
fold_ternary_loc (UNKNOWN_LOCATION, CODE, T1, T2, T3, T4)
 extern tree fold_ternary_loc (location_t, enum tree_code, tree, tree, tree, 
tree);
 #define fold_build1(c,t1,t2)\
-   fold_build1_stat_loc (UNKNOWN_LOCATION, c, t1, t2 MEM_STAT_INFO)
-#define fold_build1_loc(l,c,t1,t2)\
-   fold_build1_stat_loc (l, c, t1, t2 MEM_STAT_INFO)
-extern tree fold_build1_stat_loc (location_t, enum tree_code, tree,
- tree MEM_STAT_DECL);
+   fold_build1_loc (UNKNOWN_LOCATION, c, t1, t2 MEM_STAT_INFO)
+extern tree fold_build1_loc (location_t, enum tree_code, tree,
+tree CXX_MEM_STAT_INFO);
 #define fold_build2(c,t1,t2,t3)\
-   fold_build2_stat_loc (UNKNOWN_LOCATION, c, t1, t2, t3 MEM_STAT_INFO)
-#define fold_build2_loc(l,c,t1,t2,t3)\
-   fold_build2_stat_loc (l, c, t1, t2, t3 MEM_STAT_INFO)
-extern tree fold_build2_stat_loc (location_t, enum tree_code, tree, tree,
- tree MEM_STAT_DECL);
+   fold_build2_loc (UNKNOWN_LOCATION, c, t1, t2, t3 MEM_STAT_INFO)
+extern tree fold_build2_loc (location_t, enum tree_code, tree, tree,
+tree CXX_MEM_STAT_INFO);
 #define fold_build3(c,t1,t2,t3,t4)\
-   fold_build3_stat_loc (UNKNOWN_LOCATION, c, t1, t2, t3, t4 MEM_STAT_INFO)
-#define fold_build3_loc(l,c,t1,t2,t3,t4)\
-   fold_build3_stat_loc (l, c, t1, t2, t3, t4 MEM_STAT_INFO)
-extern tree fold_build3_stat_loc (location_t, enum tree_code, tree, tree, tree,
- tree MEM_STAT_DECL);
+   fold_build3_loc (UNKNOWN_LOCATION, c, t1, t2, t3, t4 MEM_STAT_INFO)
+extern tree fold_build3_loc (location_t, enum tree_code, tree, tree, tree,
+ tree CXX_MEM_STAT_INFO);
 extern tree fold_build1_initializer_loc (location_t, enum tree_code, tree, 
tree);
 extern tree fold_build2_initializer_loc (location_t, enum tree_code, tree, 
tree, tree);
 #define fold_build_call_array(T1,T2,N,T4)\
-- 
2.11.0



[PATCH 16/19] simplify the bitmap alloc_stat functions with c++

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/fortran/ChangeLog:

2017-07-27  Trevor Saunders  

* resolve.c (find_reachable_labels): Adjust.

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* bitmap.c (bitmap_obstack_alloc_stat): Rename to bitmap_alloc.
(bitmap_gc_alloc_stat): Rename to bitmap_gc_alloc.
* bitmap.h (bitmap_obstack_alloc_stat): Adjust prototype.
(bitmap_gc_alloc_stat): Likewise.
(BITMAP_ALLOC, BITMAP_GGC_ALLOC): Adjust.
---
 gcc/bitmap.c  |  4 ++--
 gcc/bitmap.h  | 14 --
 gcc/fortran/resolve.c |  2 +-
 3 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/gcc/bitmap.c b/gcc/bitmap.c
index 7bebeecca55..be8d0cc6247 100644
--- a/gcc/bitmap.c
+++ b/gcc/bitmap.c
@@ -273,7 +273,7 @@ bitmap_obstack_release (bitmap_obstack *bit_obstack)
it on the default bitmap obstack.  */
 
 bitmap
-bitmap_obstack_alloc_stat (bitmap_obstack *bit_obstack MEM_STAT_DECL)
+bitmap_alloc (bitmap_obstack *bit_obstack MEM_STAT_DECL)
 {
   bitmap map;
 
@@ -295,7 +295,7 @@ bitmap_obstack_alloc_stat (bitmap_obstack *bit_obstack 
MEM_STAT_DECL)
 /* Create a new GCd bitmap.  */
 
 bitmap
-bitmap_gc_alloc_stat (ALONE_MEM_STAT_DECL)
+bitmap_gc_alloc (ALONE_MEM_STAT_DECL)
 {
   bitmap map;
 
diff --git a/gcc/bitmap.h b/gcc/bitmap.h
index ad5398409d6..ca047666dc1 100644
--- a/gcc/bitmap.h
+++ b/gcc/bitmap.h
@@ -345,10 +345,10 @@ bitmap_initialize_stat (bitmap head, bitmap_obstack 
*obstack MEM_STAT_DECL)
 #define bitmap_initialize(h,o) bitmap_initialize_stat (h,o MEM_STAT_INFO)
 
 /* Allocate and free bitmaps from obstack, malloc and gc'd memory.  */
-extern bitmap bitmap_obstack_alloc_stat (bitmap_obstack *obstack 
MEM_STAT_DECL);
-#define bitmap_obstack_alloc(t) bitmap_obstack_alloc_stat (t MEM_STAT_INFO)
-extern bitmap bitmap_gc_alloc_stat (ALONE_MEM_STAT_DECL);
-#define bitmap_gc_alloc() bitmap_gc_alloc_stat (ALONE_MEM_STAT_INFO)
+extern bitmap bitmap_alloc (bitmap_obstack *obstack CXX_MEM_STAT_INFO);
+#define BITMAP_ALLOC bitmap_alloc
+extern bitmap bitmap_gc_alloc (ALONE_CXX_MEM_STAT_INFO);
+#define BITMAP_GGC_ALLOC bitmap_gc_alloc
 extern void bitmap_obstack_free (bitmap);
 
 /* A few compatibility/functions macros for compatibility with sbitmaps */
@@ -365,12 +365,6 @@ extern unsigned bitmap_last_set_bit (const_bitmap);
 /* Compute bitmap hash (for purposes of hashing etc.)  */
 extern hashval_t bitmap_hash (const_bitmap);
 
-/* Allocate a bitmap from a bit obstack.  */
-#define BITMAP_ALLOC(OBSTACK) bitmap_obstack_alloc (OBSTACK)
-
-/* Allocate a gc'd bitmap.  */
-#define BITMAP_GGC_ALLOC() bitmap_gc_alloc ()
-
 /* Do any cleanup needed on a bitmap when it is no longer used.  */
 #define BITMAP_FREE(BITMAP) \
((void) (bitmap_obstack_free ((bitmap) BITMAP), (BITMAP) = (bitmap) 
NULL))
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 12903a4390a..5caf76761ee 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -9098,7 +9098,7 @@ find_reachable_labels (gfc_code *block)
   if (!block)
 return;
 
-  cs_base->reachable_labels = bitmap_obstack_alloc (_obstack);
+  cs_base->reachable_labels = bitmap_alloc (_obstack);
 
   /* Collect labels in this block.  We don't keep those corresponding
  to END {IF|SELECT}, these are checked in resolve_branch by going
-- 
2.11.0



[PATCH 17/19] use c++ for bitmap_initialize

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* bitmap.c (bitmap_alloc): Adjust.
(bitmap_gc_alloc): Likewise.
* bitmap.h (bitmap_initialize_stat): Remove _stat from name.
---
 gcc/bitmap.c | 4 ++--
 gcc/bitmap.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/gcc/bitmap.c b/gcc/bitmap.c
index be8d0cc6247..03f6923db2f 100644
--- a/gcc/bitmap.c
+++ b/gcc/bitmap.c
@@ -284,7 +284,7 @@ bitmap_alloc (bitmap_obstack *bit_obstack MEM_STAT_DECL)
 bit_obstack->heads = (struct bitmap_head *) map->first;
   else
 map = XOBNEW (_obstack->obstack, bitmap_head);
-  bitmap_initialize_stat (map, bit_obstack PASS_MEM_STAT);
+  bitmap_initialize (map, bit_obstack PASS_MEM_STAT);
 
   if (GATHER_STATISTICS)
 register_overhead (map, sizeof (bitmap_head));
@@ -300,7 +300,7 @@ bitmap_gc_alloc (ALONE_MEM_STAT_DECL)
   bitmap map;
 
   map = ggc_alloc ();
-  bitmap_initialize_stat (map, NULL PASS_MEM_STAT);
+  bitmap_initialize (map, NULL PASS_MEM_STAT);
 
   if (GATHER_STATISTICS)
 register_overhead (map, sizeof (bitmap_head));
diff --git a/gcc/bitmap.h b/gcc/bitmap.h
index ca047666dc1..348032360f2 100644
--- a/gcc/bitmap.h
+++ b/gcc/bitmap.h
@@ -335,14 +335,13 @@ extern void dump_bitmap_statistics (void);
to allocate from, NULL for GC'd bitmap.  */
 
 static inline void
-bitmap_initialize_stat (bitmap head, bitmap_obstack *obstack MEM_STAT_DECL)
+bitmap_initialize (bitmap head, bitmap_obstack *obstack CXX_MEM_STAT_INFO)
 {
   head->first = head->current = NULL;
   head->obstack = obstack;
   if (GATHER_STATISTICS)
 bitmap_register (head PASS_MEM_STAT);
 }
-#define bitmap_initialize(h,o) bitmap_initialize_stat (h,o MEM_STAT_INFO)
 
 /* Allocate and free bitmaps from obstack, malloc and gc'd memory.  */
 extern bitmap bitmap_alloc (bitmap_obstack *obstack CXX_MEM_STAT_INFO);
-- 
2.11.0



[PATCH 15/19] replace shallow_copy_rtx_stat with c++

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* rtl.c (shallow_copy_rtx_stat): Remove _stat from name.
* rtl.h (shallow_copy_rtx): Remove macro.
---
 gcc/rtl.c | 2 +-
 gcc/rtl.h | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/gcc/rtl.c b/gcc/rtl.c
index b91172f63fa..b0f977eca9c 100644
--- a/gcc/rtl.c
+++ b/gcc/rtl.c
@@ -359,7 +359,7 @@ copy_rtx (rtx orig)
 /* Create a new copy of an rtx.  Only copy just one level.  */
 
 rtx
-shallow_copy_rtx_stat (const_rtx orig MEM_STAT_DECL)
+shallow_copy_rtx (const_rtx orig MEM_STAT_DECL)
 {
   const unsigned int size = rtx_size (orig);
   rtx const copy = ggc_alloc_rtx_def_stat (size PASS_MEM_STAT);
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 1f4b6413ca1..8a68bb152bc 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2725,8 +2725,7 @@ extern rtx copy_rtx_if_shared (rtx);
 
 /* In rtl.c */
 extern unsigned int rtx_size (const_rtx);
-extern rtx shallow_copy_rtx_stat (const_rtx MEM_STAT_DECL);
-#define shallow_copy_rtx(a) shallow_copy_rtx_stat (a MEM_STAT_INFO)
+extern rtx shallow_copy_rtx (const_rtx CXX_MEM_STAT_INFO);
 extern int rtx_equal_p (const_rtx, const_rtx);
 extern bool rtvec_all_equal_p (const_rtvec);
 
-- 
2.11.0



[PATCH 13/19] use c++ for build_tree_list{,_vec}_stat

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* tree.c (build_tree_list_vec_stat): Remove _stat from name.
(build_tree_list_stat): Likewise.
* tree.h (build_tree_list): Remove macro.
(build_tree_list_vec): Likewise.
---
 gcc/tree.c | 6 +++---
 gcc/tree.h | 6 ++
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/gcc/tree.c b/gcc/tree.c
index a7a030e25f2..0c5acd6c8a6 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -2868,7 +2868,7 @@ nreverse (tree t)
purpose and value fields are PARM and VALUE.  */
 
 tree
-build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
+build_tree_list (tree parm, tree value MEM_STAT_DECL)
 {
   tree t = make_node (TREE_LIST PASS_MEM_STAT);
   TREE_PURPOSE (t) = parm;
@@ -2879,7 +2879,7 @@ build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
 /* Build a chain of TREE_LIST nodes from a vector.  */
 
 tree
-build_tree_list_vec_stat (const vec *vec MEM_STAT_DECL)
+build_tree_list_vec (const vec *vec MEM_STAT_DECL)
 {
   tree ret = NULL_TREE;
   tree *pp = 
@@ -2887,7 +2887,7 @@ build_tree_list_vec_stat (const vec *vec 
MEM_STAT_DECL)
   tree t;
   FOR_EACH_VEC_SAFE_ELT (vec, i, t)
 {
-  *pp = build_tree_list_stat (NULL, t PASS_MEM_STAT);
+  *pp = build_tree_list (NULL, t PASS_MEM_STAT);
   pp = _CHAIN (*pp);
 }
   return ret;
diff --git a/gcc/tree.h b/gcc/tree.h
index 637e99088a1..e9e7931b1ae 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4021,10 +4021,8 @@ extern tree build_minus_one_cst (tree);
 extern tree build_all_ones_cst (tree);
 extern tree build_zero_cst (tree);
 extern tree build_string (int, const char *);
-extern tree build_tree_list_stat (tree, tree MEM_STAT_DECL);
-#define build_tree_list(t, q) build_tree_list_stat (t, q MEM_STAT_INFO)
-extern tree build_tree_list_vec_stat (const vec *MEM_STAT_DECL);
-#define build_tree_list_vec(v) build_tree_list_vec_stat (v MEM_STAT_INFO)
+extern tree build_tree_list (tree, tree CXX_MEM_STAT_INFO);
+extern tree build_tree_list_vec (const vec * CXX_MEM_STAT_INFO);
 extern tree build_decl (location_t, enum tree_code,
tree, tree CXX_MEM_STAT_INFO);
 extern tree build_fn_decl (const char *, tree);
-- 
2.11.0



[PATCH 12/19] use C++ for {make,build}_vector_stat

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* tree.c (make_vector_stat): Remove _stat from name.
(build_vector_stat): Likewise.
* tree.h (make_vector_stat): Remove macro.
(build_vector_stat): Likewise.
---
 gcc/tree.c | 4 ++--
 gcc/tree.h | 6 ++
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/gcc/tree.c b/gcc/tree.c
index e630316300f..a7a030e25f2 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -1681,7 +1681,7 @@ cst_and_fits_in_hwi (const_tree x)
 /* Build a newly constructed VECTOR_CST node of length LEN.  */
 
 tree
-make_vector_stat (unsigned len MEM_STAT_DECL)
+make_vector (unsigned len MEM_STAT_DECL)
 {
   tree t;
   unsigned length = (len - 1) * sizeof (tree) + sizeof (struct tree_vector);
@@ -1700,7 +1700,7 @@ make_vector_stat (unsigned len MEM_STAT_DECL)
are in a list pointed to by VALS.  */
 
 tree
-build_vector_stat (tree type, tree *vals MEM_STAT_DECL)
+build_vector (tree type, tree *vals MEM_STAT_DECL)
 {
   int over = 0;
   unsigned cnt = 0;
diff --git a/gcc/tree.h b/gcc/tree.h
index d765c31cda3..637e99088a1 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4002,10 +4002,8 @@ extern tree force_fit_type (tree, const wide_int_ref &, 
int, bool);
 extern tree build_int_cst (tree, HOST_WIDE_INT);
 extern tree build_int_cstu (tree type, unsigned HOST_WIDE_INT cst);
 extern tree build_int_cst_type (tree, HOST_WIDE_INT);
-extern tree make_vector_stat (unsigned MEM_STAT_DECL);
-#define make_vector(n) make_vector_stat (n MEM_STAT_INFO)
-extern tree build_vector_stat (tree, tree * MEM_STAT_DECL);
-#define build_vector(t,v) build_vector_stat (t, v MEM_STAT_INFO)
+extern tree make_vector (unsigned CXX_MEM_STAT_INFO);
+extern tree build_vector (tree, tree * CXX_MEM_STAT_INFO);
 extern tree build_vector_from_ctor (tree, vec *);
 extern tree build_vector_from_val (tree, tree);
 extern void recompute_constructor_flags (tree);
-- 
2.11.0



[PATCH 14/19] replace rtx_alloc_stat with c++

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* emit-rtl.c (gen_raw_REG): Adjust.
* gengenrtl.c (gendef): Likewise.
* rtl.c (rtx_alloc_stat): Remove _stat from name.
* rtl.h (rtx_alloc): Remove macro.
---
 gcc/emit-rtl.c  | 2 +-
 gcc/gengenrtl.c | 2 +-
 gcc/rtl.c   | 2 +-
 gcc/rtl.h   | 3 +--
 4 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 2bc5d566933..6951f61703b 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -433,7 +433,7 @@ set_mode_and_regno (rtx x, machine_mode mode, unsigned int 
regno)
 rtx
 gen_raw_REG (machine_mode mode, unsigned int regno)
 {
-  rtx x = rtx_alloc_stat (REG MEM_STAT_INFO);
+  rtx x = rtx_alloc (REG MEM_STAT_INFO);
   set_mode_and_regno (x, mode, regno);
   REG_ATTRS (x) = NULL;
   ORIGINAL_REGNO (x) = regno;
diff --git a/gcc/gengenrtl.c b/gcc/gengenrtl.c
index 19381be38d2..e23327b5cfc 100644
--- a/gcc/gengenrtl.c
+++ b/gcc/gengenrtl.c
@@ -250,7 +250,7 @@ gendef (const char *format)
  the memory and initializes it.  */
   puts ("{");
   puts ("  rtx rt;");
-  puts ("  rt = rtx_alloc_stat (code PASS_MEM_STAT);\n");
+  puts ("  rt = rtx_alloc (code PASS_MEM_STAT);\n");
 
   puts ("  PUT_MODE_RAW (rt, mode);");
 
diff --git a/gcc/rtl.c b/gcc/rtl.c
index 1f6a77aa08e..b91172f63fa 100644
--- a/gcc/rtl.c
+++ b/gcc/rtl.c
@@ -223,7 +223,7 @@ rtx_alloc_stat_v (RTX_CODE code MEM_STAT_DECL, int extra)
all the rest is initialized to zero.  */
 
 rtx
-rtx_alloc_stat (RTX_CODE code MEM_STAT_DECL)
+rtx_alloc (RTX_CODE code MEM_STAT_DECL)
 {
   return rtx_alloc_stat_v (code PASS_MEM_STAT, 0);
 }
diff --git a/gcc/rtl.h b/gcc/rtl.h
index e63dcf042cb..1f4b6413ca1 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2705,8 +2705,7 @@ extern HOST_WIDE_INT trunc_int_for_mode   (HOST_WIDE_INT, 
machine_mode);
 extern rtx plus_constant (machine_mode, rtx, HOST_WIDE_INT, bool = false);
 
 /* In rtl.c */
-extern rtx rtx_alloc_stat (RTX_CODE MEM_STAT_DECL);
-#define rtx_alloc(c) rtx_alloc_stat (c MEM_STAT_INFO)
+extern rtx rtx_alloc (RTX_CODE CXX_MEM_STAT_INFO);
 extern rtx rtx_alloc_stat_v (RTX_CODE MEM_STAT_DECL, int);
 #define rtx_alloc_v(c, SZ) rtx_alloc_stat_v (c MEM_STAT_INFO, SZ)
 #define const_wide_int_alloc(NWORDS)   \
-- 
2.11.0



[PATCH 09/19] use c++ instead of build_vl_exp_stat

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* tree.c (build_vl_exp_stat): Remove _stat from name.
* tree.h (build_vl_exp): Remove macro.
---
 gcc/tree.c | 2 +-
 gcc/tree.h | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/gcc/tree.c b/gcc/tree.c
index b763bc08969..fd25fd50157 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -11248,7 +11248,7 @@ build_omp_clause (location_t loc, enum omp_clause_code 
code)
object is initialized to zeros.  */
 
 tree
-build_vl_exp_stat (enum tree_code code, int len MEM_STAT_DECL)
+build_vl_exp (enum tree_code code, int len MEM_STAT_DECL)
 {
   tree t;
   int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
diff --git a/gcc/tree.h b/gcc/tree.h
index 1c8fd57a465..ca50de5c747 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4039,8 +4039,7 @@ extern tree build_block (tree, tree, tree, tree);
 extern tree build_empty_stmt (location_t);
 extern tree build_omp_clause (location_t, enum omp_clause_code);
 
-extern tree build_vl_exp_stat (enum tree_code, int MEM_STAT_DECL);
-#define build_vl_exp(c, n) build_vl_exp_stat (c, n MEM_STAT_INFO)
+extern tree build_vl_exp (enum tree_code, int CXX_MEM_STAT_INFO);
 
 extern tree build_call_nary (tree, tree, int, ...);
 extern tree build_call_valist (tree, tree, int, va_list);
-- 
2.11.0



[PATCH 05/19] use c++ instead of buildN_stat{,_loc}

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* fold-const.c (fold_build1_stat_loc): Adjust.
(fold_build2_stat_loc): Likewise.
(fold_build3_stat_loc): Likewise.
* tree.c (build0_stat): Remove _stat from name.
(build1_stat): Likewise.
(build2_stat): Likewise.
(build3_stat): Likewise.
(build4_stat): Likewise.
(build5_stat): Likewise.
* tree.h (build1_loc): Remove macro, and rename _stat function
to this.
(build2_loc): Likewise.
(build3_loc): Likewise.
(build4_loc): Likewise.
(build5_loc): Likewise.
---
 gcc/fold-const.c |  6 +++---
 gcc/tree.c   | 18 -
 gcc/tree.h   | 60 ++--
 3 files changed, 35 insertions(+), 49 deletions(-)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index ecba3ffada4..976924f34d7 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -1,7 +1,7 @@ fold_build1_stat_loc (location_t loc,
 
   tem = fold_unary_loc (loc, code, type, op0);
   if (!tem)
-tem = build1_stat_loc (loc, code, type, op0 PASS_MEM_STAT);
+tem = build1_loc (loc, code, type, op0 PASS_MEM_STAT);
 
 #ifdef ENABLE_FOLD_CHECKING
   md5_init_ctx ();
@@ -12268,7 +12268,7 @@ fold_build2_stat_loc (location_t loc,
 
   tem = fold_binary_loc (loc, code, type, op0, op1);
   if (!tem)
-tem = build2_stat_loc (loc, code, type, op0, op1 PASS_MEM_STAT);
+tem = build2_loc (loc, code, type, op0, op1 PASS_MEM_STAT);
 
 #ifdef ENABLE_FOLD_CHECKING
   md5_init_ctx ();
@@ -12328,7 +12328,7 @@ fold_build3_stat_loc (location_t loc, enum tree_code 
code, tree type,
   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
   tem = fold_ternary_loc (loc, code, type, op0, op1, op2);
   if (!tem)
-tem = build3_stat_loc (loc, code, type, op0, op1, op2 PASS_MEM_STAT);
+tem = build3_loc (loc, code, type, op0, op1, op2 PASS_MEM_STAT);
 
 #ifdef ENABLE_FOLD_CHECKING
   md5_init_ctx ();
diff --git a/gcc/tree.c b/gcc/tree.c
index 4b92392d6d5..bb9339030ef 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -4365,7 +4365,7 @@ do { tree _node = (NODE); \
enough for all extant tree codes.  */
 
 tree
-build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
+build0 (enum tree_code code, tree tt MEM_STAT_DECL)
 {
   tree t;
 
@@ -4378,7 +4378,7 @@ build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
 }
 
 tree
-build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL)
+build1 (enum tree_code code, tree type, tree node MEM_STAT_DECL)
 {
   int length = sizeof (struct tree_exp);
   tree t;
@@ -4454,7 +4454,7 @@ build1_stat (enum tree_code code, tree type, tree node 
MEM_STAT_DECL)
   } while (0)
 
 tree
-build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
+build2 (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
 {
   bool constant, read_only, side_effects, div_by_zero;
   tree t;
@@ -4534,8 +4534,8 @@ build2_stat (enum tree_code code, tree tt, tree arg0, 
tree arg1 MEM_STAT_DECL)
 
 
 tree
-build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
-tree arg2 MEM_STAT_DECL)
+build3 (enum tree_code code, tree tt, tree arg0, tree arg1,
+   tree arg2 MEM_STAT_DECL)
 {
   bool constant, read_only, side_effects;
   tree t;
@@ -4575,8 +4575,8 @@ build3_stat (enum tree_code code, tree tt, tree arg0, 
tree arg1,
 }
 
 tree
-build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
-tree arg2, tree arg3 MEM_STAT_DECL)
+build4 (enum tree_code code, tree tt, tree arg0, tree arg1,
+   tree arg2, tree arg3 MEM_STAT_DECL)
 {
   bool constant, read_only, side_effects;
   tree t;
@@ -4602,8 +4602,8 @@ build4_stat (enum tree_code code, tree tt, tree arg0, 
tree arg1,
 }
 
 tree
-build5_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
-tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
+build5 (enum tree_code code, tree tt, tree arg0, tree arg1,
+   tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
 {
   bool constant, read_only, side_effects;
   tree t;
diff --git a/gcc/tree.h b/gcc/tree.h
index 9b580bc3965..70803a02973 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3929,81 +3929,67 @@ extern tree grow_tree_vec_stat (tree v, int 
MEM_STAT_DECL);
 extern tree build_nt (enum tree_code, ...);
 extern tree build_nt_call_vec (tree, vec *);
 
-extern tree build0_stat (enum tree_code, tree MEM_STAT_DECL);
-#define build0(c,t) build0_stat (c,t MEM_STAT_INFO)
-extern tree build1_stat (enum tree_code, tree, tree MEM_STAT_DECL);
-#define build1(c,t1,t2) build1_stat (c,t1,t2 MEM_STAT_INFO)
-extern tree build2_stat (enum tree_code, tree, tree, tree MEM_STAT_DECL);
-#define build2(c,t1,t2,t3) build2_stat (c,t1,t2,t3 MEM_STAT_INFO)
-extern tree build3_stat (enum tree_code, tree, tree, tree, tree MEM_STAT_DECL);
-#define build3(c,t1,t2,t3,t4) build3_stat 

[PATCH 11/19] remove unused build_var_debug_value prototype

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* tree.h (build_var_debug_value): Remove prototype.
---
 gcc/tree.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/gcc/tree.h b/gcc/tree.h
index 7ecfb947fe2..d765c31cda3 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3989,10 +3989,6 @@ build5_loc (location_t loc, enum tree_code code, tree 
type, tree arg0,
   return t;
 }
 
-extern tree build_var_debug_value_stat (tree, tree MEM_STAT_DECL);
-#define build_var_debug_value(t1,t2) \
-  build_var_debug_value_stat (t1,t2 MEM_STAT_INFO)
-
 /* Constructs double_int from tree CST.  */
 
 extern tree double_int_to_tree (tree, double_int);
-- 
2.11.0



[PATCH 06/19] use c++ instead of {make,grow}_tree_vec_stat

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* tree.c (make_tree_vec_stat): Remove _stat from name.
(grow_tree_vec_stat): Likewise.
* tree.h (make_tree_vec_stat): Adjust prototype.
(grow_tree_vec_stat): Likewise.
(make_tree_vec): Remove macro.
(grow_tree_vec): Likewise.
---
 gcc/tree.c | 4 ++--
 gcc/tree.h | 6 ++
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/gcc/tree.c b/gcc/tree.c
index bb9339030ef..931f987e93a 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -2265,7 +2265,7 @@ make_int_cst (int len, int ext_len MEM_STAT_DECL)
 /* Build a newly constructed TREE_VEC node of length LEN.  */
 
 tree
-make_tree_vec_stat (int len MEM_STAT_DECL)
+make_tree_vec (int len MEM_STAT_DECL)
 {
   tree t;
   size_t length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
@@ -2283,7 +2283,7 @@ make_tree_vec_stat (int len MEM_STAT_DECL)
 /* Grow a TREE_VEC node to new length LEN.  */
 
 tree
-grow_tree_vec_stat (tree v, int len MEM_STAT_DECL)
+grow_tree_vec (tree v, int len MEM_STAT_DECL)
 {
   gcc_assert (TREE_CODE (v) == TREE_VEC);
 
diff --git a/gcc/tree.h b/gcc/tree.h
index 70803a02973..636dc0926e1 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3916,13 +3916,11 @@ extern tree make_int_cst (int, int CXX_MEM_STAT_INFO);
 
 /* Make a TREE_VEC.  */
 
-extern tree make_tree_vec_stat (int MEM_STAT_DECL);
-#define make_tree_vec(t) make_tree_vec_stat (t MEM_STAT_INFO)
+extern tree make_tree_vec (int CXX_MEM_STAT_INFO);
 
 /* Grow a TREE_VEC.  */
 
-extern tree grow_tree_vec_stat (tree v, int MEM_STAT_DECL);
-#define grow_tree_vec(v, t) grow_tree_vec_stat (v, t MEM_STAT_INFO)
+extern tree grow_tree_vec (tree v, int CXX_MEM_STAT_INFO);
 
 /* Construct various types of nodes.  */
 
-- 
2.11.0



[PATCH 04/19] use c++ for make_int_cst_stat

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* tree.c (make_int_cst_stat): Remove _stat from name.
* tree.h (make_int_cst_stat): Adjust prototype.
(make_int_cst): Remove macro.
---
 gcc/tree.c | 2 +-
 gcc/tree.h | 4 +---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/tree.c b/gcc/tree.c
index 5532b5fc1a7..4b92392d6d5 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -2235,7 +2235,7 @@ build_case_label (tree low_value, tree high_value, tree 
label_decl)
The latter determines the length of the HOST_WIDE_INT vector.  */
 
 tree
-make_int_cst_stat (int len, int ext_len MEM_STAT_DECL)
+make_int_cst (int len, int ext_len MEM_STAT_DECL)
 {
   tree t;
   int length = ((ext_len - 1) * sizeof (HOST_WIDE_INT)
diff --git a/gcc/tree.h b/gcc/tree.h
index 34c1ea31080..9b580bc3965 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3912,9 +3912,7 @@ extern tree make_tree_binfo (unsigned CXX_MEM_STAT_INFO);
 
 /* Make an INTEGER_CST.  */
 
-extern tree make_int_cst_stat (int, int MEM_STAT_DECL);
-#define make_int_cst(LEN, EXT_LEN) \
-  make_int_cst_stat (LEN, EXT_LEN MEM_STAT_INFO)
+extern tree make_int_cst (int, int CXX_MEM_STAT_INFO);
 
 /* Make a TREE_VEC.  */
 
-- 
2.11.0



[PATCH 10/19] use c++ for tree_cons_stat

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* tree.c (tree_cons_stat): Remove _stat from name.
* tree.h (tree_cons): Remove macro.
---
 gcc/tree.c | 2 +-
 gcc/tree.h | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/gcc/tree.c b/gcc/tree.c
index fd25fd50157..e630316300f 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -2898,7 +2898,7 @@ build_tree_list_vec_stat (const vec *vec 
MEM_STAT_DECL)
and whose TREE_CHAIN is CHAIN.  */
 
 tree 
-tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
+tree_cons (tree purpose, tree value, tree chain MEM_STAT_DECL)
 {
   tree node;
 
diff --git a/gcc/tree.h b/gcc/tree.h
index ca50de5c747..7ecfb947fe2 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4339,8 +4339,7 @@ extern tree chainon (tree, tree);
 
 /* Make a new TREE_LIST node from specified PURPOSE, VALUE and CHAIN.  */
 
-extern tree tree_cons_stat (tree, tree, tree MEM_STAT_DECL);
-#define tree_cons(t,q,w) tree_cons_stat (t,q,w MEM_STAT_INFO)
+extern tree tree_cons (tree, tree, tree CXX_MEM_STAT_INFO);
 
 /* Return the last tree node in a chain.  */
 
-- 
2.11.0



[PATCH 07/19] replace gimple_alloc_stat with c++

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* gimple.c (gimple_build_with_ops_stat): Adjust.
(gimple_alloc_stat): Remove _stat from name.
* gimple.h (gimple_alloc): Remove macro.
---
 gcc/gimple.c | 4 ++--
 gcc/gimple.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/gcc/gimple.c b/gcc/gimple.c
index 479f90c54c9..13a68284879 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -117,7 +117,7 @@ gimple_size (enum gimple_code code)
operands.  */
 
 gimple *
-gimple_alloc_stat (enum gimple_code code, unsigned num_ops MEM_STAT_DECL)
+gimple_alloc (enum gimple_code code, unsigned num_ops MEM_STAT_DECL)
 {
   size_t size;
   gimple *stmt;
@@ -169,7 +169,7 @@ static gimple *
 gimple_build_with_ops_stat (enum gimple_code code, unsigned subcode,
unsigned num_ops MEM_STAT_DECL)
 {
-  gimple *s = gimple_alloc_stat (code, num_ops PASS_MEM_STAT);
+  gimple *s = gimple_alloc (code, num_ops PASS_MEM_STAT);
   gimple_set_subcode (s, subcode);
 
   return s;
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 2d81eedab4a..d9945648215 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -1417,8 +1417,7 @@ extern enum gimple_statement_structure_enum const 
gss_for_code_[];
of comminucating the profile info to the builtin expanders.  */
 extern gimple *currently_expanding_gimple_stmt;
 
-#define gimple_alloc(c, n) gimple_alloc_stat (c, n MEM_STAT_INFO)
-gimple *gimple_alloc_stat (enum gimple_code, unsigned MEM_STAT_DECL);
+gimple *gimple_alloc (enum gimple_code, unsigned CXX_MEM_STAT_INFO);
 greturn *gimple_build_return (tree);
 void gimple_call_reset_alias_info (gcall *);
 gcall *gimple_build_call_vec (tree, vec );
-- 
2.11.0



[PATCH 08/19] use c++ instead of build_decl_stat

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* tree.c (build_decl_stat): Remove _stat from name.
* tree.h (build_decl): Remove macro.
---
 gcc/tree.c | 2 +-
 gcc/tree.h | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/gcc/tree.c b/gcc/tree.c
index 931f987e93a..b763bc08969 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -4740,7 +4740,7 @@ build_nt_call_vec (tree fn, vec *args)
Other slots are initialized to 0 or null pointers.  */
 
 tree
-build_decl_stat (location_t loc, enum tree_code code, tree name,
+build_decl (location_t loc, enum tree_code code, tree name,
 tree type MEM_STAT_DECL)
 {
   tree t;
diff --git a/gcc/tree.h b/gcc/tree.h
index 636dc0926e1..1c8fd57a465 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4031,10 +4031,9 @@ extern tree build_tree_list_stat (tree, tree 
MEM_STAT_DECL);
 #define build_tree_list(t, q) build_tree_list_stat (t, q MEM_STAT_INFO)
 extern tree build_tree_list_vec_stat (const vec *MEM_STAT_DECL);
 #define build_tree_list_vec(v) build_tree_list_vec_stat (v MEM_STAT_INFO)
-extern tree build_decl_stat (location_t, enum tree_code,
-tree, tree MEM_STAT_DECL);
+extern tree build_decl (location_t, enum tree_code,
+   tree, tree CXX_MEM_STAT_INFO);
 extern tree build_fn_decl (const char *, tree);
-#define build_decl(l,c,t,q) build_decl_stat (l, c, t, q MEM_STAT_INFO)
 extern tree build_translation_unit_decl (tree);
 extern tree build_block (tree, tree, tree, tree);
 extern tree build_empty_stmt (location_t);
-- 
2.11.0



[PATCH 02/19] use c++ instead of _stat for copy_node_stat

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/cp/ChangeLog:

2017-07-27  Trevor Saunders  

* lex.c (copy_decl): Adjust.
(copy_type): Likewise.

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* tree.c (copy_node_stat): Rename to copy_node.
(build_distinct_type_copy): Adjust.
* tree.h (copy_node_stat): Adjust prototype.
(copy_node): Remove macro.
---
 gcc/cp/lex.c | 4 ++--
 gcc/tree.c   | 4 ++--
 gcc/tree.h   | 3 +--
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index 961b705a546..097fbb547d2 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -766,7 +766,7 @@ copy_decl (tree decl MEM_STAT_DECL)
 {
   tree copy;
 
-  copy = copy_node_stat (decl PASS_MEM_STAT);
+  copy = copy_node (decl PASS_MEM_STAT);
   cxx_dup_lang_specific_decl (copy);
   return copy;
 }
@@ -799,7 +799,7 @@ copy_type (tree type MEM_STAT_DECL)
 {
   tree copy;
 
-  copy = copy_node_stat (type PASS_MEM_STAT);
+  copy = copy_node (type PASS_MEM_STAT);
   copy_lang_type (copy);
   return copy;
 }
diff --git a/gcc/tree.c b/gcc/tree.c
index 49c54bbb4c7..1bd4cfcc1d5 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -1128,7 +1128,7 @@ free_node (tree node)
TREE_CHAIN, if it has one, is zero and it has a fresh uid.  */
 
 tree
-copy_node_stat (tree node MEM_STAT_DECL)
+copy_node (tree node MEM_STAT_DECL)
 {
   tree t;
   enum tree_code code = TREE_CODE (node);
@@ -6684,7 +6684,7 @@ build_aligned_type (tree type, unsigned int align)
 tree
 build_distinct_type_copy (tree type MEM_STAT_DECL)
 {
-  tree t = copy_node_stat (type PASS_MEM_STAT);
+  tree t = copy_node (type PASS_MEM_STAT);
 
   TYPE_POINTER_TO (t) = 0;
   TYPE_REFERENCE_TO (t) = 0;
diff --git a/gcc/tree.h b/gcc/tree.h
index 554356c2ee1..64bc369c239 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3897,8 +3897,7 @@ extern void free_node (tree);
 
 /* Make a copy of a node, with all the same contents.  */
 
-extern tree copy_node_stat (tree MEM_STAT_DECL);
-#define copy_node(t) copy_node_stat (t MEM_STAT_INFO)
+extern tree copy_node (tree CXX_MEM_STAT_INFO);
 
 /* Make a copy of a chain of TREE_LIST nodes.  */
 
-- 
2.11.0



[PATCH 03/19] use cxx instead of make_tree_binfo_stat

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* tree.c (make_tre_binfo_stat): Remove _stat from name.
* tree.h (make_tree_binfo_stat): Adjust prototype.
(make_tree_binfo): Remove.
---
 gcc/tree.c | 2 +-
 gcc/tree.h | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/gcc/tree.c b/gcc/tree.c
index 1bd4cfcc1d5..5532b5fc1a7 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -2193,7 +2193,7 @@ build_zero_cst (tree type)
 /* Build a BINFO with LEN language slots.  */
 
 tree
-make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
+make_tree_binfo (unsigned base_binfos MEM_STAT_DECL)
 {
   tree t;
   size_t length = (offsetof (struct tree_binfo, base_binfos)
diff --git a/gcc/tree.h b/gcc/tree.h
index 64bc369c239..34c1ea31080 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3908,8 +3908,7 @@ extern tree copy_list (tree);
 extern tree build_case_label (tree, tree, tree);
 
 /* Make a BINFO.  */
-extern tree make_tree_binfo_stat (unsigned MEM_STAT_DECL);
-#define make_tree_binfo(t) make_tree_binfo_stat (t MEM_STAT_INFO)
+extern tree make_tree_binfo (unsigned CXX_MEM_STAT_INFO);
 
 /* Make an INTEGER_CST.  */
 
-- 
2.11.0



[PATCH 01/19] use c++ instead of make_node_stat

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-07-27  Trevor Saunders  

* tree.c (make_node_stat): rename to make_node.
(build_tree_list_stat): Adjust.
(build0_stat): Likewise.
(build2_stat): Likewise.
(build3_stat): Likewise.
(build4_stat): Likewise.
(build5_stat): Likewise.
(build_decl_stat): Likewise.
* tree.h (make_node_stat): Adjust prototype.
(make_node): remove macro.
---
 gcc/tree.c | 16 
 gcc/tree.h |  3 +--
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/gcc/tree.c b/gcc/tree.c
index 48fb2ce0651..49c54bbb4c7 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -997,7 +997,7 @@ allocate_decl_uid (void)
Achoo!  I got a code in the node.  */
 
 tree
-make_node_stat (enum tree_code code MEM_STAT_DECL)
+make_node (enum tree_code code MEM_STAT_DECL)
 {
   tree t;
   enum tree_code_class type = TREE_CODE_CLASS (code);
@@ -2870,7 +2870,7 @@ nreverse (tree t)
 tree
 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
 {
-  tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
+  tree t = make_node (TREE_LIST PASS_MEM_STAT);
   TREE_PURPOSE (t) = parm;
   TREE_VALUE (t) = value;
   return t;
@@ -4371,7 +4371,7 @@ build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
 
   gcc_assert (TREE_CODE_LENGTH (code) == 0);
 
-  t = make_node_stat (code PASS_MEM_STAT);
+  t = make_node (code PASS_MEM_STAT);
   TREE_TYPE (t) = tt;
 
   return t;
@@ -4474,7 +4474,7 @@ build2_stat (enum tree_code code, tree tt, tree arg0, 
tree arg1 MEM_STAT_DECL)
 gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
&& ptrofftype_p (TREE_TYPE (arg1)));
 
-  t = make_node_stat (code PASS_MEM_STAT);
+  t = make_node (code PASS_MEM_STAT);
   TREE_TYPE (t) = tt;
 
   /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
@@ -4543,7 +4543,7 @@ build3_stat (enum tree_code code, tree tt, tree arg0, 
tree arg1,
   gcc_assert (TREE_CODE_LENGTH (code) == 3);
   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
 
-  t = make_node_stat (code PASS_MEM_STAT);
+  t = make_node (code PASS_MEM_STAT);
   TREE_TYPE (t) = tt;
 
   read_only = 1;
@@ -4583,7 +4583,7 @@ build4_stat (enum tree_code code, tree tt, tree arg0, 
tree arg1,
 
   gcc_assert (TREE_CODE_LENGTH (code) == 4);
 
-  t = make_node_stat (code PASS_MEM_STAT);
+  t = make_node (code PASS_MEM_STAT);
   TREE_TYPE (t) = tt;
 
   side_effects = TREE_SIDE_EFFECTS (t);
@@ -4610,7 +4610,7 @@ build5_stat (enum tree_code code, tree tt, tree arg0, 
tree arg1,
 
   gcc_assert (TREE_CODE_LENGTH (code) == 5);
 
-  t = make_node_stat (code PASS_MEM_STAT);
+  t = make_node (code PASS_MEM_STAT);
   TREE_TYPE (t) = tt;
 
   side_effects = TREE_SIDE_EFFECTS (t);
@@ -4745,7 +4745,7 @@ build_decl_stat (location_t loc, enum tree_code code, 
tree name,
 {
   tree t;
 
-  t = make_node_stat (code PASS_MEM_STAT);
+  t = make_node (code PASS_MEM_STAT);
   DECL_SOURCE_LOCATION (t) = loc;
 
 /*  if (type == error_mark_node)
diff --git a/gcc/tree.h b/gcc/tree.h
index 819938c4458..554356c2ee1 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3889,8 +3889,7 @@ extern int allocate_decl_uid (void);
The TREE_CODE is the only argument.  Contents are initialized
to zero except for a few of the common fields.  */
 
-extern tree make_node_stat (enum tree_code MEM_STAT_DECL);
-#define make_node(t) make_node_stat (t MEM_STAT_INFO)
+extern tree make_node (enum tree_code CXX_MEM_STAT_INFO);
 
 /* Free tree node.  */
 
-- 
2.11.0



[PATCH 00/19] cleanup of memory stats prototypes

2017-07-27 Thread tbsaunde+gcc
From: Trevor Saunders 

The preC++ way of passing information about the call site of a function was to
use a macro that passed __file__, __LINE__, and __FUNCTION__ to a function with
the same name with _stat appended to it.  The way this is now done with C++ is
to have arguments where the default value is __LINE__, __FILE__, and
__FUNCTION__ in the caller.  This has the significant advantage that if you
look for "^function (" you find the correct function, where in the C way of
doing things you need to realize its a macro and check the definition of the
macro to see what to look for next.  So this removes a layer of indirection,
and makes things somewhat more consistant in using the C++ way of doing things.

patches independently bootstrapped and regtested on ppc64le-linux-gnu.  I
successfully ran make all-gcc with --enable-gather-detailed-mem-stats, but
couldn't complete a bootstrap before the series was applied, because the
ddrs_table in tree-loop-distribution.c causes memory statistics gathering to 
crash before the series as well as after it.  ok?

thanks

Trev

p.s. the issue with ddrs_table is that it ends up trying to add to the memory
stats hash table from a global constructor when that hash table hasn't yet been
constructed.


Trevor Saunders (19):
  use c++ instead of make_node_stat
  use c++ instead of _stat for copy_node_stat
  use cxx instead of make_tree_binfo_stat
  use c++ for make_int_cst_stat
  use c++ instead of buildN_stat{,_loc}
  use c++ instead of {make,grow}_tree_vec_stat
  replace gimple_alloc_stat with c++
  use c++ instead of build_decl_stat
  use c++ instead of build_vl_exp_stat
  use c++ for tree_cons_stat
  remove unused build_var_debug_value prototype
  use C++ for {make,build}_vector_stat
  use c++ for build_tree_list{,_vec}_stat
  replace rtx_alloc_stat with c++
  replace shallow_copy_rtx_stat with c++
  simplify the bitmap alloc_stat functions with c++
  use c++ for bitmap_initialize
  use c++ for gimple_build_debug_bind{,_source}
  use c++ for fold_buildN_loc

 gcc/bitmap.c  |   8 ++--
 gcc/bitmap.h  |  17 +++-
 gcc/cp/lex.c  |   4 +-
 gcc/emit-rtl.c|   2 +-
 gcc/fold-const.c  |  14 +++
 gcc/fold-const.h  |  24 +---
 gcc/fortran/resolve.c |   2 +-
 gcc/gengenrtl.c   |   2 +-
 gcc/gimple.c  |   8 ++--
 gcc/gimple.h  |  11 ++
 gcc/rtl.c |   4 +-
 gcc/rtl.h |   6 +--
 gcc/tree.c|  62 ++---
 gcc/tree.h| 106 ++
 14 files changed, 109 insertions(+), 161 deletions(-)

-- 
2.11.0



[PATCH V2] improve bitmap / sbitmap compatability of bitmap_set_bit

2017-07-24 Thread tbsaunde+gcc
From: Trevor Saunders 

This makes the sbitmap version return true if the bit was previously
unset to make it similar to the bitmap version.

I believe I fixed up the comments from may, and rebootstrapped + regtested
ppc64le-linux-gnu, ok?

Trev

gcc/ChangeLog:

2017-07-20  Trevor Saunders  

* sbitmap.h (bitmap_set_bit): Return bool similar to bitmap
version of this function.
---
 gcc/ChangeLog |  5 +
 gcc/sbitmap.h | 12 
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ef0e7881073..8d171b1a8a5 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2017-07-20  Trevor Saunders  
+
+   * sbitmap.h (bitmap_set_bit): Return bool similar to bitmap
+   version of this function.
+
 2017-07-18  Uros Bizjak  
 
PR target/81471
diff --git a/gcc/sbitmap.h b/gcc/sbitmap.h
index ce4d27d927c..6f90fc877d4 100644
--- a/gcc/sbitmap.h
+++ b/gcc/sbitmap.h
@@ -104,13 +104,17 @@ bitmap_bit_p (const_sbitmap map, int bitno)
   return (map->elms[i] >> s) & (SBITMAP_ELT_TYPE) 1;
 }
 
-/* Set bit number BITNO in the sbitmap MAP.  */
+/* Set bit number BITNO in the sbitmap MAP.  Return true if it was
+   previously unset.  */
 
-static inline void
+static inline bool
 bitmap_set_bit (sbitmap map, int bitno)
 {
-  map->elms[bitno / SBITMAP_ELT_BITS]
-|= (SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS;
+  SBITMAP_ELT_TYPE *word = >elms[bitno / SBITMAP_ELT_BITS];
+  SBITMAP_ELT_TYPE mask = (SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS;
+  bool ret = (*word & mask) == 0;
+  *word |= mask;
+  return ret;
 }
 
 /* Reset bit number BITNO in the sbitmap MAP.  */
-- 
2.11.0



[PATCH 13/13] make inverted_post_order_compute() operate on a vec

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-05-09  Trevor Saunders  

* cfganal.c (inverted_post_order_compute): Change argument type
to vec *.
* cfganal.h (inverted_post_order_compute): Adjust prototype.
* df-core.c (rest_of_handle_df_initialize): Adjust.
(rest_of_handle_df_finish): Likewise.
(df_analyze_1): Likewise.
(df_analyze): Likewise.
(loop_inverted_post_order_compute): Change argument to be a vec *.
(df_analyze_loop): Adjust.
(df_get_n_blocks): Likewise.
(df_get_postorder): Likewise.
* df.h (struct df_d): Change field to be a vec.
* lcm.c (compute_laterin): Adjust.
(compute_available): Likewise.
* lra-lives.c (lra_create_live_ranges_1): Likewise.
* tree-ssa-dce.c (remove_dead_stmt): Likewise.
* tree-ssa-pre.c (compute_antic): Likewise.
---
 gcc/cfganal.c  | 14 ++
 gcc/cfganal.h  |  2 +-
 gcc/df-core.c  | 56 +-
 gcc/df.h   |  4 +---
 gcc/lcm.c  | 14 ++
 gcc/lra-lives.c|  9 -
 gcc/tree-ssa-dce.c | 10 --
 gcc/tree-ssa-pre.c |  9 -
 8 files changed, 52 insertions(+), 66 deletions(-)

diff --git a/gcc/cfganal.c b/gcc/cfganal.c
index 27b453ca3f7..a3a6ea86994 100644
--- a/gcc/cfganal.c
+++ b/gcc/cfganal.c
@@ -790,12 +790,12 @@ dfs_find_deadend (basic_block bb)
and start looking for a "dead end" from that block
and do another inverted traversal from that block.  */
 
-int
-inverted_post_order_compute (int *post_order,
+void
+inverted_post_order_compute (vec *post_order,
 sbitmap *start_points)
 {
   basic_block bb;
-  int post_order_num = 0;
+  post_order->reserve_exact (n_basic_blocks_for_fn (cfun));
 
   if (flag_checking)
 verify_no_unreachable_blocks ();
@@ -863,13 +863,13 @@ inverted_post_order_compute (int *post_order,
time, check its predecessors.  */
stack.quick_push (ei_start (pred->preds));
   else
-post_order[post_order_num++] = pred->index;
+   post_order->quick_push (pred->index);
 }
   else
 {
  if (bb != EXIT_BLOCK_PTR_FOR_FN (cfun)
  && ei_one_before_end_p (ei))
-post_order[post_order_num++] = bb->index;
+   post_order->quick_push (bb->index);
 
   if (!ei_one_before_end_p (ei))
ei_next ( ());
@@ -927,9 +927,7 @@ inverted_post_order_compute (int *post_order,
   while (!stack.is_empty ());
 
   /* EXIT_BLOCK is always included.  */
-  post_order[post_order_num++] = EXIT_BLOCK;
-
-  return post_order_num;
+  post_order->quick_push (EXIT_BLOCK);
 }
 
 /* Compute the depth first search order of FN and store in the array
diff --git a/gcc/cfganal.h b/gcc/cfganal.h
index 7df484b8441..39bb5e547a5 100644
--- a/gcc/cfganal.h
+++ b/gcc/cfganal.h
@@ -63,7 +63,7 @@ extern void add_noreturn_fake_exit_edges (void);
 extern void connect_infinite_loops_to_exit (void);
 extern int post_order_compute (int *, bool, bool);
 extern basic_block dfs_find_deadend (basic_block);
-extern int inverted_post_order_compute (int *, sbitmap *start_points = 0);
+extern void inverted_post_order_compute (vec *postorder, sbitmap 
*start_points = 0);
 extern int pre_and_rev_post_order_compute_fn (struct function *,
  int *, int *, bool);
 extern int pre_and_rev_post_order_compute (int *, int *, bool);
diff --git a/gcc/df-core.c b/gcc/df-core.c
index 1b270d417aa..1e84d4d948f 100644
--- a/gcc/df-core.c
+++ b/gcc/df-core.c
@@ -702,10 +702,9 @@ rest_of_handle_df_initialize (void)
 df_live_add_problem ();
 
   df->postorder = XNEWVEC (int, last_basic_block_for_fn (cfun));
-  df->postorder_inverted = XNEWVEC (int, last_basic_block_for_fn (cfun));
   df->n_blocks = post_order_compute (df->postorder, true, true);
-  df->n_blocks_inverted = inverted_post_order_compute (df->postorder_inverted);
-  gcc_assert (df->n_blocks == df->n_blocks_inverted);
+  inverted_post_order_compute (>postorder_inverted);
+  gcc_assert ((unsigned) df->n_blocks == df->postorder_inverted.length ());
 
   df->hard_regs_live_count = XCNEWVEC (unsigned int, FIRST_PSEUDO_REGISTER);
 
@@ -816,7 +815,7 @@ rest_of_handle_df_finish (void)
 }
 
   free (df->postorder);
-  free (df->postorder_inverted);
+  df->postorder_inverted.release ();
   free (df->hard_regs_live_count);
   free (df);
   df = NULL;
@@ -1198,7 +1197,7 @@ df_analyze_1 (void)
   int i;
 
   /* These should be the same.  */
-  gcc_assert (df->n_blocks == df->n_blocks_inverted);
+  gcc_assert ((unsigned) df->n_blocks == df->postorder_inverted.length ());
 
   /* We need to do this before the df_verify_all because this is
  not kept incrementally up to date.  */
@@ -1222,8 +1221,8 @@ df_analyze_1 (void)

[PATCH 09/13] use auto_bitmap more with alternate obstacks

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-05-09  Trevor Saunders  

* df-core.c (df_set_blocks): Start using auto_bitmap.
(df_compact_blocks): Likewise.
* df-problems.c (df_rd_confluence_n): Likewise.
* df-scan.c (df_insn_rescan_all): Likewise.
(df_process_deferred_rescans): Likewise.
(df_update_entry_block_defs): Likewise.
(df_update_exit_block_uses): Likewise.
(df_entry_block_bitmap_verify): Likewise.
(df_exit_block_bitmap_verify): Likewise.
(df_scan_verify): Likewise.
* lra-constraints.c (lra_constraints): Likewise.
(undo_optional_reloads): Likewise.
(lra_undo_inheritance): Likewise.
* lra-remat.c (calculate_gen_cands): Likewise.
(do_remat): Likewise.
* lra-spills.c (assign_spill_hard_regs): Likewise.
(spill_pseudos): Likewise.
* tree-ssa-pre.c (bitmap_set_and): Likewise.
(bitmap_set_subtract_values): Likewise.
---
 gcc/df-core.c | 30 +++--
 gcc/df-problems.c | 10 +++---
 gcc/df-scan.c | 93 ---
 gcc/lra-constraints.c | 42 ++-
 gcc/lra-remat.c   | 43 ++--
 gcc/lra-spills.c  | 25 ++
 gcc/tree-ssa-pre.c| 17 --
 7 files changed, 104 insertions(+), 156 deletions(-)

diff --git a/gcc/df-core.c b/gcc/df-core.c
index 98787a768c6..1b270d417aa 100644
--- a/gcc/df-core.c
+++ b/gcc/df-core.c
@@ -497,9 +497,8 @@ df_set_blocks (bitmap blocks)
  /* This block is called to change the focus from one subset
 to another.  */
  int p;
- bitmap_head diff;
- bitmap_initialize (, _bitmap_obstack);
- bitmap_and_compl (, df->blocks_to_analyze, blocks);
+ auto_bitmap diff (_bitmap_obstack);
+ bitmap_and_compl (diff, df->blocks_to_analyze, blocks);
  for (p = 0; p < df->num_problems_defined; p++)
{
  struct dataflow *dflow = df->problems_in_order[p];
@@ -510,7 +509,7 @@ df_set_blocks (bitmap blocks)
  bitmap_iterator bi;
  unsigned int bb_index;
 
- EXECUTE_IF_SET_IN_BITMAP (, 0, bb_index, bi)
+ EXECUTE_IF_SET_IN_BITMAP (diff, 0, bb_index, bi)
{
  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
  if (bb)
@@ -522,8 +521,6 @@ df_set_blocks (bitmap blocks)
}
}
}
-
-  bitmap_clear ();
}
   else
{
@@ -1652,9 +1649,8 @@ df_compact_blocks (void)
   int i, p;
   basic_block bb;
   void *problem_temps;
-  bitmap_head tmp;
 
-  bitmap_initialize (, _bitmap_obstack);
+  auto_bitmap tmp (_bitmap_obstack);
   for (p = 0; p < df->num_problems_defined; p++)
 {
   struct dataflow *dflow = df->problems_in_order[p];
@@ -1663,17 +1659,17 @@ df_compact_blocks (void)
 dflow problem.  */
   if (dflow->out_of_date_transfer_functions)
{
- bitmap_copy (, dflow->out_of_date_transfer_functions);
+ bitmap_copy (tmp, dflow->out_of_date_transfer_functions);
  bitmap_clear (dflow->out_of_date_transfer_functions);
- if (bitmap_bit_p (, ENTRY_BLOCK))
+ if (bitmap_bit_p (tmp, ENTRY_BLOCK))
bitmap_set_bit (dflow->out_of_date_transfer_functions, ENTRY_BLOCK);
- if (bitmap_bit_p (, EXIT_BLOCK))
+ if (bitmap_bit_p (tmp, EXIT_BLOCK))
bitmap_set_bit (dflow->out_of_date_transfer_functions, EXIT_BLOCK);
 
  i = NUM_FIXED_BLOCKS;
  FOR_EACH_BB_FN (bb, cfun)
{
- if (bitmap_bit_p (, bb->index))
+ if (bitmap_bit_p (tmp, bb->index))
bitmap_set_bit (dflow->out_of_date_transfer_functions, i);
  i++;
}
@@ -1711,23 +1707,21 @@ df_compact_blocks (void)
 
   if (df->blocks_to_analyze)
 {
-  if (bitmap_bit_p (, ENTRY_BLOCK))
+  if (bitmap_bit_p (tmp, ENTRY_BLOCK))
bitmap_set_bit (df->blocks_to_analyze, ENTRY_BLOCK);
-  if (bitmap_bit_p (, EXIT_BLOCK))
+  if (bitmap_bit_p (tmp, EXIT_BLOCK))
bitmap_set_bit (df->blocks_to_analyze, EXIT_BLOCK);
-  bitmap_copy (, df->blocks_to_analyze);
+  bitmap_copy (tmp, df->blocks_to_analyze);
   bitmap_clear (df->blocks_to_analyze);
   i = NUM_FIXED_BLOCKS;
   FOR_EACH_BB_FN (bb, cfun)
{
- if (bitmap_bit_p (, bb->index))
+ if (bitmap_bit_p (tmp, bb->index))
bitmap_set_bit (df->blocks_to_analyze, i);
  i++;
}
 }
 
-  bitmap_clear ();
-
   i = NUM_FIXED_BLOCKS;
   FOR_EACH_BB_FN (bb, cfun)
 {
diff --git a/gcc/df-problems.c b/gcc/df-problems.c
index 92323a39d8a..755aecf46df 100644
--- a/gcc/df-problems.c
+++ b/gcc/df-problems.c
@@ -461,19 +461,17 @@ df_rd_confluence_n (edge e)
   

[PATCH 07/13] use auto_bitmap more

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-05-09  Trevor Saunders  

* bt-load.c (combine_btr_defs): Use auto_bitmap to manage bitmap
lifetime.
(migrate_btr_def): Likewise.
* cfgloop.c (get_loop_body_in_bfs_order): Likewise.
* df-core.c (loop_post_order_compute): Likewise.
(loop_inverted_post_order_compute): Likewise.
* hsa-common.h: Likewise.
* hsa-gen.c (hsa_bb::~hsa_bb): Likewise.
* init-regs.c (initialize_uninitialized_regs): Likewise.
* ipa-inline.c (resolve_noninline_speculation): Likewise.
(inline_small_functions): Likewise.
* ipa-reference.c (ipa_reference_write_optimization_summary):
Likewise.
* ira.c (combine_and_move_insns): Likewise.
(build_insn_chain): Likewise.
* loop-invariant.c (find_invariants): Likewise.
* lower-subreg.c (propagate_pseudo_copies): Likewise.
* predict.c (tree_predict_by_opcode): Likewise.
(predict_paths_leading_to): Likewise.
(predict_paths_leading_to_edge): Likewise.
(estimate_loops_at_level): Likewise.
(estimate_loops): Likewise.
* shrink-wrap.c (try_shrink_wrapping): Likewise.
(spread_components): Likewise.
* tree-cfg.c (remove_edge_and_dominated_blocks): Likewise.
* tree-loop-distribution.c (rdg_build_partitions): Likewise.
* tree-predcom.c (tree_predictive_commoning_loop): Likewise.
* tree-ssa-coalesce.c (coalesce_ssa_name): Likewise.
* tree-ssa-phionlycprop.c (pass_phi_only_cprop::execute):
Likewise.
* tree-ssa-pre.c (remove_dead_inserted_code): Likewise.
* tree-ssa-sink.c (nearest_common_dominator_of_uses): Likewise.
* tree-ssa-threadupdate.c (compute_path_counts): Likewise.
(mark_threaded_blocks): Likewise.
(thread_through_all_blocks): Likewise.
* tree-ssa.c (verify_ssa): Likewise.
(execute_update_addresses_taken): Likewise.
* tree-ssanames.c (verify_ssaname_freelists): Likewise.
---
 gcc/bt-load.c|  8 +++-
 gcc/cfgloop.c|  4 +---
 gcc/df-core.c|  8 ++--
 gcc/hsa-common.h |  4 ++--
 gcc/hsa-gen.c| 14 ++
 gcc/init-regs.c  |  4 +---
 gcc/ipa-inline.c |  6 ++
 gcc/ipa-reference.c  |  3 +--
 gcc/ira.c| 13 -
 gcc/loop-invariant.c | 12 
 gcc/lower-subreg.c   |  8 +---
 gcc/predict.c| 19 +--
 gcc/shrink-wrap.c| 10 +++---
 gcc/tree-cfg.c   |  7 +--
 gcc/tree-loop-distribution.c |  4 +---
 gcc/tree-predcom.c   |  4 +---
 gcc/tree-ssa-coalesce.c  |  4 +---
 gcc/tree-ssa-phionlycprop.c  | 15 ---
 gcc/tree-ssa-pre.c   |  4 +---
 gcc/tree-ssa-sink.c  |  9 +++--
 gcc/tree-ssa-threadupdate.c  | 13 +++--
 gcc/tree-ssa.c   | 12 
 gcc/tree-ssanames.c  | 10 +++---
 23 files changed, 53 insertions(+), 142 deletions(-)

diff --git a/gcc/bt-load.c b/gcc/bt-load.c
index 27be6a382c4..32924e2ecc5 100644
--- a/gcc/bt-load.c
+++ b/gcc/bt-load.c
@@ -1058,7 +1058,7 @@ combine_btr_defs (btr_def *def, HARD_REG_SET 
*btrs_live_in_range)
 target registers live over the merged range.  */
  int btr;
  HARD_REG_SET combined_btrs_live;
- bitmap combined_live_range = BITMAP_ALLOC (NULL);
+ auto_bitmap combined_live_range;
  btr_user *user;
 
  if (other_def->live_range == NULL)
@@ -1116,7 +1116,6 @@ combine_btr_defs (btr_def *def, HARD_REG_SET 
*btrs_live_in_range)
  delete_insn (other_def->insn);
 
}
- BITMAP_FREE (combined_live_range);
}
 }
 }
@@ -1255,7 +1254,6 @@ can_move_up (const_basic_block bb, const rtx_insn *insn, 
int n_insns)
 static int
 migrate_btr_def (btr_def *def, int min_cost)
 {
-  bitmap live_range;
   HARD_REG_SET btrs_live_in_range;
   int btr_used_near_def = 0;
   int def_basic_block_freq;
@@ -1289,7 +1287,7 @@ migrate_btr_def (btr_def *def, int min_cost)
 }
 
   btr_def_live_range (def, _live_in_range);
-  live_range = BITMAP_ALLOC (NULL);
+  auto_bitmap live_range;
   bitmap_copy (live_range, def->live_range);
 
 #ifdef INSN_SCHEDULING
@@ -1373,7 +1371,7 @@ migrate_btr_def (btr_def *def, int min_cost)
   if (dump_file)
fprintf (dump_file, "failed to move\n");
 }
-  BITMAP_FREE (live_range);
+
   return !give_up;
 }
 
diff --git a/gcc/cfgloop.c b/gcc/cfgloop.c
index afd56bb8cf7..654d188e8b5 100644
--- a/gcc/cfgloop.c
+++ b/gcc/cfgloop.c
@@ -923,7 +923,6 @@ get_loop_body_in_bfs_order (const struct loop *loop)
 {
   basic_block *blocks;
   basic_block bb;
-  bitmap visited;
   unsigned int i = 1;
   unsigned int vc = 0;
 
@@ -931,7 +930,7 @@ get_loop_body_in_bfs_order (const 

[PATCH 12/13] make depth_first_search_ds a class

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-05-09  Trevor Saunders  

* cfganal.c (connect_infinite_loops_to_exit): Adjust.
(depth_first_search::depth_first_search): Change structure init
function to this constructor.
(depth_first_search::add_bb): Rename function to this member.
(depth_first_search::execute): Likewise.
(flow_dfs_compute_reverse_finish): Adjust.
---
 gcc/cfganal.c | 96 +--
 1 file changed, 34 insertions(+), 62 deletions(-)

diff --git a/gcc/cfganal.c b/gcc/cfganal.c
index 1b01564e8c7..27b453ca3f7 100644
--- a/gcc/cfganal.c
+++ b/gcc/cfganal.c
@@ -28,25 +28,24 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfganal.h"
 #include "cfgloop.h"
 
+namespace {
 /* Store the data structures necessary for depth-first search.  */
-struct depth_first_search_ds {
-  /* stack for backtracking during the algorithm */
-  basic_block *stack;
+class depth_first_search
+  {
+public:
+depth_first_search ();
+
+basic_block execute (basic_block);
+void add_bb (basic_block);
 
-  /* number of edges in the stack.  That is, positions 0, ..., sp-1
- have edges.  */
-  unsigned int sp;
+private:
+  /* stack for backtracking during the algorithm */
+  auto_vec m_stack;
 
   /* record of basic blocks already seen by depth-first search */
-  sbitmap visited_blocks;
+  auto_sbitmap m_visited_blocks;
 };
-
-static void flow_dfs_compute_reverse_init (depth_first_search_ds *);
-static void flow_dfs_compute_reverse_add_bb (depth_first_search_ds *,
-basic_block);
-static basic_block flow_dfs_compute_reverse_execute (depth_first_search_ds *,
-basic_block);
-static void flow_dfs_compute_reverse_finish (depth_first_search_ds *);
+}
 
 /* Mark the back edges in DFS traversal.
Return nonzero if a loop (natural or otherwise) is present.
@@ -597,30 +596,23 @@ add_noreturn_fake_exit_edges (void)
 void
 connect_infinite_loops_to_exit (void)
 {
-  basic_block unvisited_block = EXIT_BLOCK_PTR_FOR_FN (cfun);
-  basic_block deadend_block;
-  depth_first_search_ds dfs_ds;
-
   /* Perform depth-first search in the reverse graph to find nodes
  reachable from the exit block.  */
-  flow_dfs_compute_reverse_init (_ds);
-  flow_dfs_compute_reverse_add_bb (_ds, EXIT_BLOCK_PTR_FOR_FN (cfun));
+  depth_first_search dfs;
+  dfs.add_bb (EXIT_BLOCK_PTR_FOR_FN (cfun));
 
   /* Repeatedly add fake edges, updating the unreachable nodes.  */
+  basic_block unvisited_block = EXIT_BLOCK_PTR_FOR_FN (cfun);
   while (1)
 {
-  unvisited_block = flow_dfs_compute_reverse_execute (_ds,
- unvisited_block);
+  unvisited_block = dfs.execute (unvisited_block);
   if (!unvisited_block)
break;
 
-  deadend_block = dfs_find_deadend (unvisited_block);
+  basic_block deadend_block = dfs_find_deadend (unvisited_block);
   make_edge (deadend_block, EXIT_BLOCK_PTR_FOR_FN (cfun), EDGE_FAKE);
-  flow_dfs_compute_reverse_add_bb (_ds, deadend_block);
+  dfs.add_bb (deadend_block);
 }
-
-  flow_dfs_compute_reverse_finish (_ds);
-  return;
 }
 
 /* Compute reverse top sort order.  This is computing a post order
@@ -1094,31 +1086,22 @@ pre_and_rev_post_order_compute (int *pre_order, int 
*rev_post_order,
search context.  If INITIALIZE_STACK is nonzero, there is an
element on the stack.  */
 
-static void
-flow_dfs_compute_reverse_init (depth_first_search_ds *data)
+depth_first_search::depth_first_search () :
+  m_stack (n_basic_blocks_for_fn (cfun)),
+  m_visited_blocks (last_basic_block_for_fn (cfun))
 {
-  /* Allocate stack for back-tracking up CFG.  */
-  data->stack = XNEWVEC (basic_block, n_basic_blocks_for_fn (cfun));
-  data->sp = 0;
-
-  /* Allocate bitmap to track nodes that have been visited.  */
-  data->visited_blocks = sbitmap_alloc (last_basic_block_for_fn (cfun));
-
-  /* None of the nodes in the CFG have been visited yet.  */
-  bitmap_clear (data->visited_blocks);
-
-  return;
+  bitmap_clear (m_visited_blocks);
 }
 
 /* Add the specified basic block to the top of the dfs data
structures.  When the search continues, it will start at the
block.  */
 
-static void
-flow_dfs_compute_reverse_add_bb (depth_first_search_ds *data, basic_block bb)
+void
+depth_first_search::add_bb (basic_block bb)
 {
-  data->stack[data->sp++] = bb;
-  bitmap_set_bit (data->visited_blocks, bb->index);
+  m_stack.quick_push (bb);
+  bitmap_set_bit (m_visited_blocks, bb->index);
 }
 
 /* Continue the depth-first search through the reverse graph starting with the
@@ -1126,42 +1109,31 @@ flow_dfs_compute_reverse_add_bb (depth_first_search_ds 
*data, basic_block bb)
are marked.  Returns an unvisited basic block, or NULL if there is none
available.  */
 
-static 

[PATCH 11/13] make more vars auto_sbitmaps

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-05-09  Trevor Saunders  

* ddg.c (find_nodes_on_paths): Use auto_sbitmap.
(longest_simple_path): Likewise.
* shrink-wrap.c (spread_components): Likewise.
(disqualify_problematic_components): Likewise.
(emit_common_heads_for_components): Likewise.
(emit_common_tails_for_components): Likewise.
(insert_prologue_epilogue_for_components): Likewise.
---
 gcc/ddg.c | 26 --
 gcc/shrink-wrap.c | 38 +++---
 2 files changed, 19 insertions(+), 45 deletions(-)

diff --git a/gcc/ddg.c b/gcc/ddg.c
index 9ea98d6f40f..8aaed80dec4 100644
--- a/gcc/ddg.c
+++ b/gcc/ddg.c
@@ -1081,16 +1081,15 @@ free_ddg_all_sccs (ddg_all_sccs_ptr all_sccs)
 int
 find_nodes_on_paths (sbitmap result, ddg_ptr g, sbitmap from, sbitmap to)
 {
-  int answer;
   int change;
   unsigned int u = 0;
   int num_nodes = g->num_nodes;
   sbitmap_iterator sbi;
 
-  sbitmap workset = sbitmap_alloc (num_nodes);
-  sbitmap reachable_from = sbitmap_alloc (num_nodes);
-  sbitmap reach_to = sbitmap_alloc (num_nodes);
-  sbitmap tmp = sbitmap_alloc (num_nodes);
+  auto_sbitmap workset (num_nodes);
+  auto_sbitmap reachable_from (num_nodes);
+  auto_sbitmap reach_to (num_nodes);
+  auto_sbitmap tmp (num_nodes);
 
   bitmap_copy (reachable_from, from);
   bitmap_copy (tmp, from);
@@ -1150,12 +1149,7 @@ find_nodes_on_paths (sbitmap result, ddg_ptr g, sbitmap 
from, sbitmap to)
}
 }
 
-  answer = bitmap_and (result, reachable_from, reach_to);
-  sbitmap_free (workset);
-  sbitmap_free (reachable_from);
-  sbitmap_free (reach_to);
-  sbitmap_free (tmp);
-  return answer;
+  return bitmap_and (result, reachable_from, reach_to);
 }
 
 
@@ -1195,10 +1189,9 @@ longest_simple_path (struct ddg * g, int src, int dest, 
sbitmap nodes)
   int i;
   unsigned int u = 0;
   int change = 1;
-  int result;
   int num_nodes = g->num_nodes;
-  sbitmap workset = sbitmap_alloc (num_nodes);
-  sbitmap tmp = sbitmap_alloc (num_nodes);
+  auto_sbitmap workset (num_nodes);
+  auto_sbitmap tmp (num_nodes);
 
 
   /* Data will hold the distance of the longest path found so far from
@@ -1224,10 +1217,7 @@ longest_simple_path (struct ddg * g, int src, int dest, 
sbitmap nodes)
  change |= update_dist_to_successors (u_node, nodes, tmp);
}
 }
-  result = g->nodes[dest].aux.count;
-  sbitmap_free (workset);
-  sbitmap_free (tmp);
-  return result;
+  return g->nodes[dest].aux.count;
 }
 
 #endif /* INSN_SCHEDULING */
diff --git a/gcc/shrink-wrap.c b/gcc/shrink-wrap.c
index 492376d949b..1ac4ea3b054 100644
--- a/gcc/shrink-wrap.c
+++ b/gcc/shrink-wrap.c
@@ -1264,7 +1264,7 @@ spread_components (sbitmap components)
   todo.create (n_basic_blocks_for_fn (cfun));
   auto_bitmap seen;
 
-  sbitmap old = sbitmap_alloc (SBITMAP_SIZE (components));
+  auto_sbitmap old (SBITMAP_SIZE (components));
 
   /* Find for every block the components that are *not* needed on some path
  from the entry to that block.  Do this with a flood fill from the entry
@@ -1390,8 +1390,6 @@ spread_components (sbitmap components)
  fprintf (dump_file, "\n");
}
 }
-
-  sbitmap_free (old);
 }
 
 /* If we cannot handle placing some component's prologues or epilogues where
@@ -1400,8 +1398,8 @@ spread_components (sbitmap components)
 static void
 disqualify_problematic_components (sbitmap components)
 {
-  sbitmap pro = sbitmap_alloc (SBITMAP_SIZE (components));
-  sbitmap epi = sbitmap_alloc (SBITMAP_SIZE (components));
+  auto_sbitmap pro (SBITMAP_SIZE (components));
+  auto_sbitmap epi (SBITMAP_SIZE (components));
 
   basic_block bb;
   FOR_EACH_BB_FN (bb, cfun)
@@ -1466,9 +1464,6 @@ disqualify_problematic_components (sbitmap components)
}
}
 }
-
-  sbitmap_free (pro);
-  sbitmap_free (epi);
 }
 
 /* Place code for prologues and epilogues for COMPONENTS where we can put
@@ -1476,9 +1471,9 @@ disqualify_problematic_components (sbitmap components)
 static void
 emit_common_heads_for_components (sbitmap components)
 {
-  sbitmap pro = sbitmap_alloc (SBITMAP_SIZE (components));
-  sbitmap epi = sbitmap_alloc (SBITMAP_SIZE (components));
-  sbitmap tmp = sbitmap_alloc (SBITMAP_SIZE (components));
+  auto_sbitmap pro (SBITMAP_SIZE (components));
+  auto_sbitmap epi (SBITMAP_SIZE (components));
+  auto_sbitmap tmp (SBITMAP_SIZE (components));
 
   basic_block bb;
   FOR_ALL_BB_FN (bb, cfun)
@@ -1554,10 +1549,6 @@ emit_common_heads_for_components (sbitmap components)
  bitmap_ior (SW (bb)->head_components, SW (bb)->head_components, epi);
}
 }
-
-  sbitmap_free (pro);
-  sbitmap_free (epi);
-  sbitmap_free (tmp);
 }
 
 /* Place code for prologues and epilogues for COMPONENTS where we can put
@@ -1565,9 +1556,9 @@ emit_common_heads_for_components (sbitmap components)
 static void
 emit_common_tails_for_components (sbitmap 

[PATCH 08/13] move several bitmaps from gc memory to the default obstack and use auto_bitmap

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

These places where probably trying to use the default bitmap obstack,
but passing 0 to bitmap_initialize actually uses gc allocation.  In any
case they are all cleaned up before going out of scope so using
auto_bitmap should be fine.

gcc/ChangeLog:

2017-05-09  Trevor Saunders  

* haifa-sched.c (estimate_shadow_tick): Replace manual bitmap
management with auto_bitmap.
(fix_inter_tick): Likewise.
(fix_recovery_deps): Likewise.
* ira.c (add_store_equivs): Likewise.
(find_moveable_pseudos): Likewise.
(split_live_ranges_for_shrink_wrap): Likewise.
* print-rtl.c (rtx_reuse_manager::rtx_reuse_manager): Likewise.
(rtx_reuse_manager::seen_def_p): Likewise.
(rtx_reuse_manager::set_seen_def): Likewise.
* print-rtl.h (class rtx_reuse_manager): Likewise.
---
 gcc/haifa-sched.c | 23 +--
 gcc/ira.c | 84 +++
 gcc/print-rtl.c   |  5 ++--
 gcc/print-rtl.h   |  2 +-
 4 files changed, 38 insertions(+), 76 deletions(-)

diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c
index 0ebf110471c..1fcc01d04ae 100644
--- a/gcc/haifa-sched.c
+++ b/gcc/haifa-sched.c
@@ -4843,14 +4843,12 @@ estimate_insn_tick (bitmap processed, rtx_insn *insn, 
int budget)
 static int
 estimate_shadow_tick (struct delay_pair *p)
 {
-  bitmap_head processed;
+  auto_bitmap processed;
   int t;
   bool cutoff;
-  bitmap_initialize (, 0);
 
-  cutoff = !estimate_insn_tick (, p->i2,
+  cutoff = !estimate_insn_tick (processed, p->i2,
max_insn_queue_index + pair_delay (p));
-  bitmap_clear ();
   if (cutoff)
 return max_insn_queue_index;
   t = INSN_TICK_ESTIMATE (p->i2) - (clock_var + pair_delay (p) + 1);
@@ -7515,15 +7513,13 @@ static void
 fix_inter_tick (rtx_insn *head, rtx_insn *tail)
 {
   /* Set of instructions with corrected INSN_TICK.  */
-  bitmap_head processed;
+  auto_bitmap processed;
   /* ??? It is doubtful if we should assume that cycle advance happens on
  basic block boundaries.  Basically insns that are unconditionally ready
  on the start of the block are more preferable then those which have
  a one cycle dependency over insn from the previous block.  */
   int next_clock = clock_var + 1;
 
-  bitmap_initialize (, 0);
-
   /* Iterates over scheduled instructions and fix their INSN_TICKs and
  INSN_TICKs of dependent instructions, so that INSN_TICKs are consistent
  across different blocks.  */
@@ -7539,7 +7535,7 @@ fix_inter_tick (rtx_insn *head, rtx_insn *tail)
  gcc_assert (tick >= MIN_TICK);
 
  /* Fix INSN_TICK of instruction from just scheduled block.  */
- if (bitmap_set_bit (, INSN_LUID (head)))
+ if (bitmap_set_bit (processed, INSN_LUID (head)))
{
  tick -= next_clock;
 
@@ -7563,7 +7559,7 @@ fix_inter_tick (rtx_insn *head, rtx_insn *tail)
  /* If NEXT has its INSN_TICK calculated, fix it.
 If not - it will be properly calculated from
 scratch later in fix_tick_ready.  */
- && bitmap_set_bit (, INSN_LUID (next)))
+ && bitmap_set_bit (processed, INSN_LUID (next)))
{
  tick -= next_clock;
 
@@ -7580,7 +7576,6 @@ fix_inter_tick (rtx_insn *head, rtx_insn *tail)
}
}
 }
-  bitmap_clear ();
 }
 
 /* Check if NEXT is ready to be added to the ready or queue list.
@@ -8617,9 +8612,7 @@ fix_recovery_deps (basic_block rec)
 {
   rtx_insn *note, *insn, *jump;
   auto_vec ready_list;
-  bitmap_head in_ready;
-
-  bitmap_initialize (_ready, 0);
+  auto_bitmap in_ready;
 
   /* NOTE - a basic block note.  */
   note = NEXT_INSN (BB_HEAD (rec));
@@ -8642,7 +8635,7 @@ fix_recovery_deps (basic_block rec)
{
  sd_delete_dep (sd_it);
 
- if (bitmap_set_bit (_ready, INSN_LUID (consumer)))
+ if (bitmap_set_bit (in_ready, INSN_LUID (consumer)))
ready_list.safe_push (consumer);
}
  else
@@ -8657,8 +8650,6 @@ fix_recovery_deps (basic_block rec)
 }
   while (insn != note);
 
-  bitmap_clear (_ready);
-
   /* Try to add instructions to the ready or queue list.  */
   unsigned int i;
   rtx_insn *temp;
diff --git a/gcc/ira.c b/gcc/ira.c
index c9751ce81ba..36a779bd37f 100644
--- a/gcc/ira.c
+++ b/gcc/ira.c
@@ -3635,16 +3635,15 @@ update_equiv_regs (void)
 static void
 add_store_equivs (void)
 {
-  bitmap_head seen_insns;
+  auto_bitmap seen_insns;
 
-  bitmap_initialize (_insns, NULL);
   for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
 {
   rtx set, src, dest;
   unsigned regno;
   rtx_insn *init_insn;
 
-  bitmap_set_bit (_insns, INSN_UID (insn));
+  bitmap_set_bit (seen_insns, INSN_UID (insn));
 
   if (! INSN_P (insn))
continue;

[PATCH 10/13] make a member an auto_sbitmap

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-05-09  Trevor Saunders  

* tree-ssa-dse.c (dse_dom_walker): Make m_live_byes a
auto_sbitmap.
---
 gcc/tree-ssa-dse.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c
index 90230abe822..3ebc19948e1 100644
--- a/gcc/tree-ssa-dse.c
+++ b/gcc/tree-ssa-dse.c
@@ -601,16 +601,14 @@ class dse_dom_walker : public dom_walker
 {
 public:
   dse_dom_walker (cdi_direction direction)
-: dom_walker (direction), m_byte_tracking_enabled (false)
-
-  { m_live_bytes = sbitmap_alloc (PARAM_VALUE (PARAM_DSE_MAX_OBJECT_SIZE)); }
-
-  ~dse_dom_walker () { sbitmap_free (m_live_bytes); }
+: dom_walker (direction),
+m_live_bytes (PARAM_VALUE (PARAM_DSE_MAX_OBJECT_SIZE)),
+m_byte_tracking_enabled (false) {}
 
   virtual edge before_dom_children (basic_block);
 
 private:
-  sbitmap m_live_bytes;
+  auto_sbitmap m_live_bytes;
   bool m_byte_tracking_enabled;
   void dse_optimize_stmt (gimple_stmt_iterator *);
 };
-- 
2.11.0



[PATCH 04/13] allow auto_bitmap to use other bitmap obstacks

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-05-07  Trevor Saunders  

* bitmap.h (class auto_bitmap): New constructor taking
bitmap_obstack * argument.
---
 gcc/bitmap.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/bitmap.h b/gcc/bitmap.h
index 49aec001cb0..2ddeee6bc10 100644
--- a/gcc/bitmap.h
+++ b/gcc/bitmap.h
@@ -824,6 +824,7 @@ class auto_bitmap
 {
  public:
   auto_bitmap () { bitmap_initialize (_bits, _default_obstack); }
+  explicit auto_bitmap (bitmap_obstack *o) { bitmap_initialize (_bits, o); }
   ~auto_bitmap () { bitmap_clear (_bits); }
   // Allow calling bitmap functions on our bitmap.
   operator bitmap () { return _bits; }
-- 
2.11.0



[PATCH 06/13] replace some manual stacks with auto_vec

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2017-05-09  Trevor Saunders  

* cfganal.c (mark_dfs_back_edges): Replace manual stack with
auto_vec.
(post_order_compute): Likewise.
(inverted_post_order_compute): Likewise.
(pre_and_rev_post_order_compute_fn): Likewise.
---
 gcc/cfganal.c | 92 +++
 1 file changed, 36 insertions(+), 56 deletions(-)

diff --git a/gcc/cfganal.c b/gcc/cfganal.c
index 7377a7a0434..1b01564e8c7 100644
--- a/gcc/cfganal.c
+++ b/gcc/cfganal.c
@@ -61,10 +61,8 @@ static void flow_dfs_compute_reverse_finish 
(depth_first_search_ds *);
 bool
 mark_dfs_back_edges (void)
 {
-  edge_iterator *stack;
   int *pre;
   int *post;
-  int sp;
   int prenum = 1;
   int postnum = 1;
   bool found = false;
@@ -74,8 +72,7 @@ mark_dfs_back_edges (void)
   post = XCNEWVEC (int, last_basic_block_for_fn (cfun));
 
   /* Allocate stack for back-tracking up CFG.  */
-  stack = XNEWVEC (edge_iterator, n_basic_blocks_for_fn (cfun) + 1);
-  sp = 0;
+  auto_vec stack (n_basic_blocks_for_fn (cfun) + 1);
 
   /* Allocate bitmap to track nodes that have been visited.  */
   auto_sbitmap visited (last_basic_block_for_fn (cfun));
@@ -84,16 +81,15 @@ mark_dfs_back_edges (void)
   bitmap_clear (visited);
 
   /* Push the first edge on to the stack.  */
-  stack[sp++] = ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs);
+  stack.quick_push (ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs));
 
-  while (sp)
+  while (!stack.is_empty ())
 {
-  edge_iterator ei;
   basic_block src;
   basic_block dest;
 
   /* Look at the edge on the top of the stack.  */
-  ei = stack[sp - 1];
+  edge_iterator ei = stack.last ();
   src = ei_edge (ei)->src;
   dest = ei_edge (ei)->dest;
   ei_edge (ei)->flags &= ~EDGE_DFS_BACK;
@@ -110,7 +106,7 @@ mark_dfs_back_edges (void)
{
  /* Since the DEST node has been visited for the first
 time, check its successors.  */
- stack[sp++] = ei_start (dest->succs);
+ stack.quick_push (ei_start (dest->succs));
}
  else
post[dest->index] = postnum++;
@@ -128,15 +124,14 @@ mark_dfs_back_edges (void)
post[src->index] = postnum++;
 
  if (!ei_one_before_end_p (ei))
-   ei_next ([sp - 1]);
+   ei_next ( ());
  else
-   sp--;
+   stack.pop ();
}
 }
 
   free (pre);
   free (post);
-  free (stack);
 
   return found;
 }
@@ -637,8 +632,6 @@ int
 post_order_compute (int *post_order, bool include_entry_exit,
bool delete_unreachable)
 {
-  edge_iterator *stack;
-  int sp;
   int post_order_num = 0;
   int count;
 
@@ -646,8 +639,7 @@ post_order_compute (int *post_order, bool 
include_entry_exit,
 post_order[post_order_num++] = EXIT_BLOCK;
 
   /* Allocate stack for back-tracking up CFG.  */
-  stack = XNEWVEC (edge_iterator, n_basic_blocks_for_fn (cfun) + 1);
-  sp = 0;
+  auto_vec stack (n_basic_blocks_for_fn (cfun) + 1);
 
   /* Allocate bitmap to track nodes that have been visited.  */
   auto_sbitmap visited (last_basic_block_for_fn (cfun));
@@ -656,16 +648,15 @@ post_order_compute (int *post_order, bool 
include_entry_exit,
   bitmap_clear (visited);
 
   /* Push the first edge on to the stack.  */
-  stack[sp++] = ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs);
+  stack.quick_push (ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs));
 
-  while (sp)
+  while (!stack.is_empty ())
 {
-  edge_iterator ei;
   basic_block src;
   basic_block dest;
 
   /* Look at the edge on the top of the stack.  */
-  ei = stack[sp - 1];
+  edge_iterator ei = stack.last ();
   src = ei_edge (ei)->src;
   dest = ei_edge (ei)->dest;
 
@@ -679,7 +670,7 @@ post_order_compute (int *post_order, bool 
include_entry_exit,
  if (EDGE_COUNT (dest->succs) > 0)
/* Since the DEST node has been visited for the first
   time, check its successors.  */
-   stack[sp++] = ei_start (dest->succs);
+   stack.quick_push (ei_start (dest->succs));
  else
post_order[post_order_num++] = dest->index;
}
@@ -690,9 +681,9 @@ post_order_compute (int *post_order, bool 
include_entry_exit,
post_order[post_order_num++] = src->index;
 
  if (!ei_one_before_end_p (ei))
-   ei_next ([sp - 1]);
+   ei_next ( ());
  else
-   sp--;
+   stack.pop ();
}
 }
 
@@ -722,7 +713,6 @@ post_order_compute (int *post_order, bool 
include_entry_exit,
   tidy_fallthru_edges ();
 }
 
-  free (stack);
   return post_order_num;
 }
 
@@ -813,16 +803,13 @@ inverted_post_order_compute (int *post_order,
 sbitmap *start_points)
 {
   basic_block bb;
-  edge_iterator 

[PATCH 05/13] allow constructing a auto_vec with a preallocation, and a possibly larger actual allocation size

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

This allows us to set the capacity of the vector when we construct it,
and still use a stack buffer when the size is small enough.

gcc/ChangeLog:

2017-05-09  Trevor Saunders  

* genrecog.c (int_set::int_set): Explicitly construct our
auto_vec base class.
* vec.h (auto_vec::auto_vec): New constructor.
---
 gcc/genrecog.c |  8 +---
 gcc/vec.h  | 12 
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/gcc/genrecog.c b/gcc/genrecog.c
index 6a9e610e7a0..b69043f0d02 100644
--- a/gcc/genrecog.c
+++ b/gcc/genrecog.c
@@ -1407,14 +1407,16 @@ struct int_set : public auto_vec 
   iterator end ();
 };
 
-int_set::int_set () {}
+int_set::int_set () : auto_vec () {}
 
-int_set::int_set (uint64_t label)
+int_set::int_set (uint64_t label) :
+  auto_vec ()
 {
   safe_push (label);
 }
 
-int_set::int_set (const int_set )
+int_set::int_set (const int_set ) :
+  auto_vec ()
 {
   safe_splice (other);
 }
diff --git a/gcc/vec.h b/gcc/vec.h
index fee46164b01..914f89c350c 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -1272,6 +1272,18 @@ public:
 this->m_vec = _auto;
   }
 
+  auto_vec (size_t s)
+  {
+if (s > N)
+  {
+   this->create (s);
+   return;
+  }
+
+m_auto.embedded_init (MAX (N, 2), 0, 1);
+this->m_vec = _auto;
+  }
+
   ~auto_vec ()
   {
 this->release ();
-- 
2.11.0



[PATCH 03/13] store the bitmap_head within the auto_bitmap

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

This gets rid of one allocation per bitmap.  Often the bitmap_head is
now on the stack, when it isn't its part of some other struct on the
heap instead of being refered to by that struct.  On 64 bit platforms
this will increase the size of such structs by 24 bytes, but its an over
all win since we don't need an 8 byte pointer pointing at the
bitmap_head.  Given that the auto_bitmap owns the bitmap_head anyway we
know there would never be a place where two auto_bitmaps would refer to
the same bitmap_head object.

gcc/ChangeLog:

2017-05-07  Trevor Saunders  

* bitmap.h (class auto_bitmap): Change type of m_bits to
bitmap_head, and adjust ctor / dtor and member operators.
---
 gcc/bitmap.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/bitmap.h b/gcc/bitmap.h
index 7508239cff9..49aec001cb0 100644
--- a/gcc/bitmap.h
+++ b/gcc/bitmap.h
@@ -823,10 +823,10 @@ bmp_iter_and_compl (bitmap_iterator *bi, unsigned *bit_no)
 class auto_bitmap
 {
  public:
-  auto_bitmap () { bits = BITMAP_ALLOC (NULL); }
-  ~auto_bitmap () { BITMAP_FREE (bits); }
+  auto_bitmap () { bitmap_initialize (_bits, _default_obstack); }
+  ~auto_bitmap () { bitmap_clear (_bits); }
   // Allow calling bitmap functions on our bitmap.
-  operator bitmap () { return bits; }
+  operator bitmap () { return _bits; }
 
  private:
   // Prevent making a copy that references our bitmap.
@@ -837,7 +837,7 @@ class auto_bitmap
   auto_bitmap  = (auto_bitmap &&);
 #endif
 
-  bitmap bits;
+  bitmap_head m_bits;
 };
 
 #endif /* GCC_BITMAP_H */
-- 
2.11.0



[PATCH 00/13] misc data structure stuff

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

Hi,

this is sort of a grab bag, but mostly improving bitmaps and auto_vec, and then
using them in more places.  Individually patches commit messages should explain 
in more detail where needed.

patches individually bootstrapped and regtested on x86_64-linux-gnu, ok?

Thanks!

Trev


Trevor Saunders (13):
  improve safety of freeing bitmaps
  improve bitmap / sbitmap compatability of bitmap_set_bit
  store the bitmap_head within the auto_bitmap
  allow auto_bitmap to use other bitmap obstacks
  allow constructing a auto_vec with a preallocation, and a possibly
larger actual allocation size
  replace some manual stacks with auto_vec
  use auto_bitmap more
  move several bitmaps from gc memory to the default obstack and use
auto_bitmap
  use auto_bitmap more with alternate obstacks
  make a member an auto_sbitmap
  make more vars auto_sbitmaps
  make depth_first_search_ds a class
  make inverted_post_order_compute() operate on a vec

 gcc/bitmap.h |  30 +--
 gcc/bt-load.c|   8 +-
 gcc/cfganal.c| 202 ---
 gcc/cfganal.h|   2 +-
 gcc/cfgloop.c|   4 +-
 gcc/ddg.c|  26 ++
 gcc/df-core.c|  94 +---
 gcc/df-problems.c|  10 +--
 gcc/df-scan.c|  93 
 gcc/df.h |   4 +-
 gcc/genrecog.c   |   8 +-
 gcc/haifa-sched.c|  23 ++---
 gcc/hsa-common.h |   4 +-
 gcc/hsa-gen.c|  14 +--
 gcc/init-regs.c  |   4 +-
 gcc/ipa-inline.c |   6 +-
 gcc/ipa-reference.c  |   3 +-
 gcc/ira.c|  97 +++--
 gcc/lcm.c|  14 ++-
 gcc/loop-invariant.c |  12 +--
 gcc/lower-subreg.c   |   8 +-
 gcc/lra-constraints.c|  42 -
 gcc/lra-lives.c  |   9 +-
 gcc/lra-remat.c  |  43 -
 gcc/lra-spills.c |  25 +++---
 gcc/predict.c|  19 ++--
 gcc/print-rtl.c  |   5 +-
 gcc/print-rtl.h  |   2 +-
 gcc/sbitmap.h|  16 +++-
 gcc/shrink-wrap.c|  48 +++---
 gcc/tree-cfg.c   |   7 +-
 gcc/tree-loop-distribution.c |   4 +-
 gcc/tree-predcom.c   |   4 +-
 gcc/tree-ssa-coalesce.c  |   4 +-
 gcc/tree-ssa-dce.c   |  10 +--
 gcc/tree-ssa-dse.c   |  10 +--
 gcc/tree-ssa-phionlycprop.c  |  15 +---
 gcc/tree-ssa-pre.c   |  30 +++
 gcc/tree-ssa-sink.c  |   9 +-
 gcc/tree-ssa-threadupdate.c  |  13 +--
 gcc/tree-ssa.c   |  12 +--
 gcc/tree-ssanames.c  |  10 +--
 gcc/vec.h|  12 +++
 43 files changed, 393 insertions(+), 622 deletions(-)

-- 
2.11.0



[PATCH 02/13] improve bitmap / sbitmap compatability of bitmap_set_bit

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

This make the sbitmap version return true if the bit was previously
unset to make it similar to the bitmap version.

gcc/ChangeLog:

2017-05-09  Trevor Saunders  

* sbitmap.h (bitmap_set_bit): Return bool similar to bitmap
version of this function.
---
 gcc/sbitmap.h | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/sbitmap.h b/gcc/sbitmap.h
index cba0452cdb9..d4e3177d495 100644
--- a/gcc/sbitmap.h
+++ b/gcc/sbitmap.h
@@ -108,11 +108,14 @@ bitmap_bit_p (const_sbitmap map, int bitno)
 
 /* Set bit number BITNO in the sbitmap MAP.  */
 
-static inline void
+static inline bool
 bitmap_set_bit (sbitmap map, int bitno)
 {
-  map->elms[bitno / SBITMAP_ELT_BITS]
-|= (SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS;
+  SBITMAP_ELT_TYPE  = map->elms[bitno / SBITMAP_ELT_BITS];
+SBITMAP_ELT_TYPE mask = (SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS;
+bool ret = (word & mask) == 0;
+word |= mask;
+return ret;
 }
 
 /* Reset bit number BITNO in the sbitmap MAP.  */
-- 
2.11.0



[PATCH 01/13] improve safety of freeing bitmaps

2017-05-09 Thread tbsaunde+gcc
From: Trevor Saunders 

There's two groups of changes here, first taking a sbitmap &, so that we
can assign null to the pointer after freeing the sbitmap to prevent use
after free through that pointer.  Second we define overloads of
sbitmap_free and bitmap_free taking auto_sbitmap and auto_bitmap
respectively, so that you can't double free the bitmap owned by a
auto_{s,}bitmap.

gcc/ChangeLog:

2017-05-09  Trevor Saunders  

* bitmap.h (BITMAP_FREE): Convert from macro to inline function
and add overloaded decl for auto_bitmap.
* sbitmap.h (inline void sbitmap_free): Add overload for
auto_sbitmap, and change sbitmap to  point to null.
---
 gcc/bitmap.h  | 21 +++--
 gcc/sbitmap.h |  7 ++-
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/gcc/bitmap.h b/gcc/bitmap.h
index f158b447357..7508239cff9 100644
--- a/gcc/bitmap.h
+++ b/gcc/bitmap.h
@@ -129,6 +129,8 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "obstack.h"
 
+   class auto_bitmap;
+
 /* Bitmap memory usage.  */
 struct bitmap_usage: public mem_usage
 {
@@ -372,8 +374,23 @@ extern hashval_t bitmap_hash (const_bitmap);
 #define BITMAP_GGC_ALLOC() bitmap_gc_alloc ()
 
 /* Do any cleanup needed on a bitmap when it is no longer used.  */
-#define BITMAP_FREE(BITMAP) \
-   ((void) (bitmap_obstack_free ((bitmap) BITMAP), (BITMAP) = (bitmap) 
NULL))
+inline void
+BITMAP_FREE (bitmap )
+{
+  bitmap_obstack_free ((bitmap) b);
+  b = NULL;
+}
+
+inline void
+BITMAP_FREE (void *)
+{
+  bitmap_obstack_free ((bitmap) b);
+  b = NULL;
+}
+
+/* Intentionally unimplemented to ensure it is never called with an
+   auto_bitmap argument.  */
+void BITMAP_FREE (auto_bitmap);
 
 /* Iterator for bitmaps.  */
 
diff --git a/gcc/sbitmap.h b/gcc/sbitmap.h
index ce4d27d927c..cba0452cdb9 100644
--- a/gcc/sbitmap.h
+++ b/gcc/sbitmap.h
@@ -82,6 +82,8 @@ along with GCC; see the file COPYING3.  If not see
 #define SBITMAP_ELT_BITS (HOST_BITS_PER_WIDEST_FAST_INT * 1u)
 #define SBITMAP_ELT_TYPE unsigned HOST_WIDEST_FAST_INT
 
+class auto_sbitmap;
+
 struct simple_bitmap_def
 {
   unsigned int n_bits; /* Number of bits.  */
@@ -208,11 +210,14 @@ bmp_iter_next (sbitmap_iterator *i, unsigned *bit_no 
ATTRIBUTE_UNUSED)
bmp_iter_next (&(ITER), &(BITNUM)))
 #endif
 
-inline void sbitmap_free (sbitmap map)
+inline void sbitmap_free (sbitmap )
 {
   free (map);
+  map = NULL;
 }
 
+void sbitmap_free (auto_sbitmap);
+
 inline void sbitmap_vector_free (sbitmap * vec)
 {
   free (vec);
-- 
2.11.0



[PATCH, RFC] warn about raw pointers that can be unique_ptr

2017-05-07 Thread tbsaunde+gcc
From: Trevor Saunders 

Hi,

This is a start at warning about various resource allocation issues that can be
improved.  Currently it only warns about functions that call malloc and then
always pass the resulting pointer to free().

It should be pretty simple to extend this to new/delete and new[]/delete[], as
well as checking that in simple cases the pairing is correct.  However it
wasn't obvious to me how to tell if a function call is to a allocating operator
new.  We probably don't want to warn about placement new since complicated
things can be happening there.  There is the DECL_IS_OPERATOR_NEW() but that
doesn't seem to cover class specific operator new overloads, and maybe even
custom ones at global scope?

Other things that may be reasonable to try and include would be open / close
and locks.

It might also be good to warn about functions that take or return unique
ownership of resources, but I'm not quiet sure how to handle functions that
allocate or deallocate shared resources.

bootstrapped but not yet regtested other than the included test on
x86_64-linux-gnu.  All comments and suggestions welcome.

Trev


  ---
 gcc/Makefile.in  |   1 +
 gcc/c-family/c.opt   |   4 +
 gcc/gimple-owned-ptr.c   | 214 +++
 gcc/passes.def   |   1 +
 gcc/testsuite/g++.dg/warn/Wowning-ptr1.C |  76 +++
 gcc/tree-pass.h  |   1 +
 6 files changed, 297 insertions(+)
 create mode 100644 gcc/gimple-owned-ptr.c
 create mode 100644 gcc/testsuite/g++.dg/warn/Wowning-ptr1.C

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index f675e073ecc..d33e8591b03 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1294,6 +1294,7 @@ OBJS = \
gimple-laddress.o \
gimple-low.o \
gimple-pretty-print.o \
+   gimple-owned-ptr.o \
gimple-ssa-backprop.o \
gimple-ssa-isolate-paths.o \
gimple-ssa-nonnull-compare.o \
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 8697eb13108..6f12c3ac5eb 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -428,6 +428,10 @@ Wctor-dtor-privacy
 C++ ObjC++ Var(warn_ctor_dtor_privacy) Warning
 Warn when all constructors and destructors are private.
 
+Wowning-ptr
+C++ ObjC++ Var(warn_owning_ptr) Warning
+Warn about pointers that can be marked as owning the resource they refer to.
+
 Wdangling-else
 C ObjC C++ ObjC++ Var(warn_dangling_else) Warning LangEnabledBy(C ObjC C++ 
ObjC++,Wparentheses)
 Warn about dangling else.
diff --git a/gcc/gimple-owned-ptr.c b/gcc/gimple-owned-ptr.c
new file mode 100644
index 000..f1283940920
--- /dev/null
+++ b/gcc/gimple-owned-ptr.c
@@ -0,0 +1,214 @@
+/* Detection of allocations that are owned by a single function.
+   Copyright (C) 2015-2017 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 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "backend.h"
+#include "tree.h"
+#include "gimple.h"
+#include "basic-block.h"
+#include "options.h"
+#include "flags.h"
+#include "stmt.h"
+#include "gimple-iterator.h"
+#include "tree-cfg.h"
+#include "tree-pass.h"
+#include "ssa.h"
+#include "diagnostic-core.h"
+
+/*  Return true if gcall calls a function in the malloc family where the memory
+ *  can be released by calling free().  */
+
+static bool
+is_malloc_alloc (gcall *call)
+{
+  if (!gimple_call_builtin_p (call))
+return false;
+
+  tree callee = gimple_call_fndecl (call);
+  built_in_function builtin = DECL_FUNCTION_CODE (callee);
+  if (builtin != BUILT_IN_MALLOC
+  && builtin != BUILT_IN_CALLOC
+  && builtin != BUILT_IN_ALIGNED_ALLOC)
+return false;
+
+  return true;
+}
+
+/* A free_fn_p implementation for free().  We don't need to check what's being
+   passed to free() because the resource in question is used in the statement,
+   and free() should only use one thing.  */
+
+static bool
+is_malloc_free (gcall *call, tree)
+{
+  return gimple_call_builtin_p (call, BUILT_IN_FREE);
+}
+
+namespace {
+
+class pass_owned_ptrs : public gimple_opt_pass
+{
+public:
+  pass_owned_ptrs (gcc::context *ctxt) : gimple_opt_pass (data, ctxt) {}
+
+  static const pass_data data;
+  virtual bool
+  gate (function *)
+  {
+return true;
+  }
+  virtual unsigned int
+  execute (function *fun);
+

[PATCH] remove conditional compilation of HAVE_AS_LEB128 code

2016-11-14 Thread tbsaunde+gcc
From: tbsaunde 

Last patch I'm squeezing in for stage 1.  Jeff approved this back in september,
but I never committed it for some reason.  So I updated it to trunk,
rebootstrapped and regtested and committed it.

Thanks!

Trev

gcc/ChangeLog:

2016-08-20  Trevor Saunders  

* acinclude.m4 (gcc_GAS_CHECK_FEATURE): Support doing an action
if the feature isn't available.
* configure: Regenerate.
* configure.ac: define HAVE_AS_LEB128 to 0 when not available.
* dwarf2asm.c (dw2_asm_output_data_uleb128): Always compile code
for HAVE_AS_LEB128.
(dw2_asm_output_data_sleb128): Likewise.
(dw2_asm_output_delta_uleb128): Likewise.
(dw2_asm_output_delta_sleb128): Likewise.
* except.c (output_one_function_exception_table): Likewise.
(dw2_size_of_call_site_table): Likewise.
(sjlj_size_of_call_site_table): Likewise.
* dwarf2out.c (output_loc_list): Likewise.
(output_rnglists): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@242381 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/acinclude.m4 |   4 ++
 gcc/configure| 106 +++-
 gcc/configure.ac |   2 +
 gcc/dwarf2asm.c  | 184 +++
 gcc/dwarf2out.c  | 153 ++---
 gcc/except.c | 162 
 6 files changed, 357 insertions(+), 254 deletions(-)

diff --git a/gcc/acinclude.m4 b/gcc/acinclude.m4
index 38dd899..791f2a7 100644
--- a/gcc/acinclude.m4
+++ b/gcc/acinclude.m4
@@ -550,6 +550,10 @@ AC_CACHE_CHECK([assembler for $1], [$2],
 ifelse([$7],,,[dnl
 if test $[$2] = yes; then
   $7
+fi])
+ifelse([$8],,,[dnl
+if test $[$2] != yes; then
+  $8
 fi])])
 
 dnl gcc_SUN_LD_VERSION
diff --git a/gcc/configure b/gcc/configure
index 0f04033..197a152 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -22432,6 +22432,7 @@ $as_echo "#define HAVE_GAS_BALIGN_AND_P2ALIGN 1" 
>>confdefs.h
 
 fi
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .p2align with 
maximum skip" >&5
 $as_echo_n "checking assembler for .p2align with maximum skip... " >&6; }
 if test "${gcc_cv_as_max_skip_p2align+set}" = set; then :
@@ -22467,6 +22468,7 @@ $as_echo "#define HAVE_GAS_MAX_SKIP_P2ALIGN 1" 
>>confdefs.h
 
 fi
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .literal16" >&5
 $as_echo_n "checking assembler for .literal16... " >&6; }
 if test "${gcc_cv_as_literal16+set}" = set; then :
@@ -22502,6 +22504,7 @@ $as_echo "#define HAVE_GAS_LITERAL16 1" >>confdefs.h
 
 fi
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for working 
.subsection -1" >&5
 $as_echo_n "checking assembler for working .subsection -1... " >&6; }
 if test "${gcc_cv_as_subsection_m1+set}" = set; then :
@@ -22549,6 +22552,7 @@ $as_echo "#define HAVE_GAS_SUBSECTION_ORDERING 1" 
>>confdefs.h
 
 fi
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .weak" >&5
 $as_echo_n "checking assembler for .weak... " >&6; }
 if test "${gcc_cv_as_weak+set}" = set; then :
@@ -22584,6 +22588,7 @@ $as_echo "#define HAVE_GAS_WEAK 1" >>confdefs.h
 
 fi
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .weakref" >&5
 $as_echo_n "checking assembler for .weakref... " >&6; }
 if test "${gcc_cv_as_weakref+set}" = set; then :
@@ -22619,6 +22624,7 @@ $as_echo "#define HAVE_GAS_WEAKREF 1" >>confdefs.h
 
 fi
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .nsubspa 
comdat" >&5
 $as_echo_n "checking assembler for .nsubspa comdat... " >&6; }
 if test "${gcc_cv_as_nsubspa_comdat+set}" = set; then :
@@ -22655,6 +22661,7 @@ $as_echo "#define HAVE_GAS_NSUBSPA_COMDAT 1" 
>>confdefs.h
 
 fi
 
+
 # .hidden needs to be supported in both the assembler and the linker,
 # because GNU LD versions before 2.12.1 have buggy support for STV_HIDDEN.
 # This is irritatingly difficult to feature test for; we have to check the
@@ -22702,6 +22709,7 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_hidden" >&5
 $as_echo "$gcc_cv_as_hidden" >&6; }
 
+
 case "${target}" in
   *-*-darwin*)
 # Darwin as has some visibility support, though with a different syntax.
@@ -23157,6 +23165,11 @@ if test $gcc_cv_as_leb128 = yes; then
 $as_echo "#define HAVE_AS_LEB128 1" >>confdefs.h
 
 fi
+if test $gcc_cv_as_leb128 != yes; then
+
+$as_echo "#define HAVE_AS_LEB128 0" >>confdefs.h
+
+fi
 
 # Check if we have assembler support for unwind directives.
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for cfi 
directives" >&5
@@ -23236,6 +23249,7 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_cfi_directive" >&5
 $as_echo "$gcc_cv_as_cfi_directive" >&6; }
 
+
 if test $gcc_cv_as_cfi_directive = yes && test x$gcc_cv_objdump != x; then
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for 

[PATCH 09/11] make add_int_reg_note take rtx_insn *

2016-11-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-11-14  Trevor Saunders  

* rtl.h: Adjust prototype.
* rtlanal.c (add_int_reg_note): Change argument type to rtx_insn *.
---
 gcc/rtl.h | 2 +-
 gcc/rtlanal.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/rtl.h b/gcc/rtl.h
index c6c30b5..efb8127 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -3017,7 +3017,7 @@ extern int find_reg_fusage (const_rtx, enum rtx_code, 
const_rtx);
 extern int find_regno_fusage (const_rtx, enum rtx_code, unsigned int);
 extern rtx alloc_reg_note (enum reg_note, rtx, rtx);
 extern void add_reg_note (rtx, enum reg_note, rtx);
-extern void add_int_reg_note (rtx, enum reg_note, int);
+extern void add_int_reg_note (rtx_insn *, enum reg_note, int);
 extern void add_shallow_copy_of_reg_note (rtx_insn *, rtx);
 extern rtx duplicate_reg_note (rtx);
 extern void remove_note (rtx_insn *, const_rtx);
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index 504b265..75dde3d 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -2286,7 +2286,7 @@ add_reg_note (rtx insn, enum reg_note kind, rtx datum)
 /* Add an integer register note with kind KIND and datum DATUM to INSN.  */
 
 void
-add_int_reg_note (rtx insn, enum reg_note kind, int datum)
+add_int_reg_note (rtx_insn *insn, enum reg_note kind, int datum)
 {
   gcc_checking_assert (int_reg_note_p (kind));
   REG_NOTES (insn) = gen_rtx_INT_LIST ((machine_mode) kind,
-- 
2.9.3.dirty



[PATCH 07/11] remove cast from emit_libcall_block

2016-11-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-11-14  Trevor Saunders  

* optabs.c (emit_libcall_block): Change argument type to
rtx_insn *.
* optabs.h: Adjust prototype.
---
 gcc/optabs.c | 5 ++---
 gcc/optabs.h | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/gcc/optabs.c b/gcc/optabs.c
index 7a1f025..2c7ca25 100644
--- a/gcc/optabs.c
+++ b/gcc/optabs.c
@@ -3681,10 +3681,9 @@ emit_libcall_block_1 (rtx_insn *insns, rtx target, rtx 
result, rtx equiv,
 }
 
 void
-emit_libcall_block (rtx insns, rtx target, rtx result, rtx equiv)
+emit_libcall_block (rtx_insn *insns, rtx target, rtx result, rtx equiv)
 {
-  emit_libcall_block_1 (safe_as_a  (insns),
-   target, result, equiv, false);
+  emit_libcall_block_1 (insns, target, result, equiv, false);
 }
 
 /* Nonzero if we can perform a comparison of mode MODE straightforwardly.
diff --git a/gcc/optabs.h b/gcc/optabs.h
index 03fd94d..9ab8cb1 100644
--- a/gcc/optabs.h
+++ b/gcc/optabs.h
@@ -224,7 +224,7 @@ extern bool maybe_emit_unop_insn (enum insn_code, rtx, rtx, 
enum rtx_code);
 extern void emit_unop_insn (enum insn_code, rtx, rtx, enum rtx_code);
 
 /* Emit code to make a call to a constant function or a library call.  */
-extern void emit_libcall_block (rtx, rtx, rtx, rtx);
+extern void emit_libcall_block (rtx_insn *, rtx, rtx, rtx);
 
 /* The various uses that a comparison can have; used by can_compare_p:
jumps, conditional moves, store flag operations.  */
-- 
2.9.3.dirty



[PATCH 08/11] make prologue_epilogue_contains take a rtx_insn *

2016-11-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-11-14  Trevor Saunders  

* function.c (contains): Change argument type to rtx_insn *.
(prologue_contains): Likewise.
(epilogue_contains): Likewise.
(prologue_epilogue_contains): Likewise.
* function.h: Adjust prototype.
---
 gcc/function.c | 12 ++--
 gcc/function.h |  6 +++---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/gcc/function.c b/gcc/function.c
index 0b1d168..ab76a26 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -142,7 +142,7 @@ extern tree debug_find_var_in_block_tree (tree, tree);
can always export `prologue_epilogue_contains'.  */
 static void record_insns (rtx_insn *, rtx, hash_table **)
  ATTRIBUTE_UNUSED;
-static bool contains (const_rtx, hash_table *);
+static bool contains (const rtx_insn *, hash_table *);
 static void prepare_function_start (void);
 static void do_clobber_return_reg (rtx, void *);
 static void do_use_return_reg (rtx, void *);
@@ -5733,7 +5733,7 @@ maybe_copy_prologue_epilogue_insn (rtx insn, rtx copy)
we can be running after reorg, SEQUENCE rtl is possible.  */
 
 static bool
-contains (const_rtx insn, hash_table *hash)
+contains (const rtx_insn *insn, hash_table *hash)
 {
   if (hash == NULL)
 return false;
@@ -5748,23 +5748,23 @@ contains (const_rtx insn, hash_table 
*hash)
   return false;
 }
 
-  return hash->find (const_cast (insn)) != NULL;
+  return hash->find (const_cast (insn)) != NULL;
 }
 
 int
-prologue_contains (const_rtx insn)
+prologue_contains (const rtx_insn *insn)
 {
   return contains (insn, prologue_insn_hash);
 }
 
 int
-epilogue_contains (const_rtx insn)
+epilogue_contains (const rtx_insn *insn)
 {
   return contains (insn, epilogue_insn_hash);
 }
 
 int
-prologue_epilogue_contains (const_rtx insn)
+prologue_epilogue_contains (const rtx_insn *insn)
 {
   if (contains (insn, prologue_insn_hash))
 return 1;
diff --git a/gcc/function.h b/gcc/function.h
index e854c7f..163ad0c 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -628,9 +628,9 @@ extern void clobber_return_register (void);
 extern void expand_function_end (void);
 extern rtx get_arg_pointer_save_area (void);
 extern void maybe_copy_prologue_epilogue_insn (rtx, rtx);
-extern int prologue_contains (const_rtx);
-extern int epilogue_contains (const_rtx);
-extern int prologue_epilogue_contains (const_rtx);
+extern int prologue_contains (const rtx_insn *);
+extern int epilogue_contains (const rtx_insn *);
+extern int prologue_epilogue_contains (const rtx_insn *);
 extern void record_prologue_seq (rtx_insn *);
 extern void record_epilogue_seq (rtx_insn *);
 extern void emit_return_into_block (bool simple_p, basic_block bb);
-- 
2.9.3.dirty



[PATCH 11/11] make find_reg{,no}_fusage take rtx_insn *

2016-11-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-11-14  Trevor Saunders  

* config/arm/arm-protos.h: Adjust prototype.
* config/arm/arm.c (use_return_insn): Change argument type to
rtx_insn *.
* rtl.h (is_a_helper ::test): New specialization.
* rtlanal.c (reg_set_p): Adjust.
(find_reg_fusage): Change argument type to rtx_insn *.
(find_regno_fusage): Likewise.
---
 gcc/config/arm/arm-protos.h |  2 +-
 gcc/config/arm/arm.c|  2 +-
 gcc/rtl.h   | 12 ++--
 gcc/rtlanal.c   | 23 +--
 4 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h
index 95bae5e..539588b 100644
--- a/gcc/config/arm/arm-protos.h
+++ b/gcc/config/arm/arm-protos.h
@@ -23,7 +23,7 @@
 #define GCC_ARM_PROTOS_H
 
 extern enum unwind_info_type arm_except_unwind_info (struct gcc_options *);
-extern int use_return_insn (int, rtx);
+extern int use_return_insn (int, rtx_insn *);
 extern bool use_simple_return_p (void);
 extern enum reg_class arm_regno_class (int);
 extern void arm_load_pic_register (unsigned long);
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 3e63330..7f8ab8e 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -3737,7 +3737,7 @@ arm_trampoline_adjust_address (rtx addr)
call.  SIBLING is the call insn, so we can examine its register usage.  */
 
 int
-use_return_insn (int iscond, rtx sibling)
+use_return_insn (int iscond, rtx_insn *sibling)
 {
   int regno;
   unsigned int func_type;
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 03c1157..f8b6b95 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -907,6 +907,14 @@ is_a_helper ::test (rtx rt)
 template <>
 template <>
 inline bool
+is_a_helper ::test (const_rtx rt)
+{
+  return CALL_P (rt);
+}
+
+template <>
+template <>
+inline bool
 is_a_helper ::test (rtx_insn *insn)
 {
   return CALL_P (insn);
@@ -3013,8 +3021,8 @@ extern rtx find_reg_note (const_rtx, enum reg_note, 
const_rtx);
 extern rtx find_regno_note (const_rtx, enum reg_note, unsigned int);
 extern rtx find_reg_equal_equiv_note (const rtx_insn *);
 extern rtx find_constant_src (const rtx_insn *);
-extern int find_reg_fusage (const_rtx, enum rtx_code, const_rtx);
-extern int find_regno_fusage (const_rtx, enum rtx_code, unsigned int);
+extern int find_reg_fusage (const rtx_insn *, enum rtx_code, const_rtx);
+extern int find_regno_fusage (const rtx_insn *, enum rtx_code, unsigned int);
 extern rtx alloc_reg_note (enum reg_note, rtx, rtx);
 extern void add_reg_note (rtx, enum reg_note, rtx);
 extern void add_int_reg_note (rtx_insn *, enum reg_note, int);
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index 9cd24bb..e85da56 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -1196,14 +1196,17 @@ reg_set_p (const_rtx reg, const_rtx insn)
   /* We can be passed an insn or part of one.  If we are passed an insn,
  check if a side-effect of the insn clobbers REG.  */
   if (INSN_P (insn)
-  && (FIND_REG_INC_NOTE (insn, reg)
- || (CALL_P (insn)
- && ((REG_P (reg)
-  && REGNO (reg) < FIRST_PSEUDO_REGISTER
-  && overlaps_hard_reg_set_p (regs_invalidated_by_call,
-  GET_MODE (reg), REGNO (reg)))
- || MEM_P (reg)
- || find_reg_fusage (insn, CLOBBER, reg)
+  && FIND_REG_INC_NOTE (insn, reg))
+return true;
+
+  const rtx_call_insn *call = dyn_cast (insn);
+  if (call
+  && ((REG_P (reg)
+  && REGNO (reg) < FIRST_PSEUDO_REGISTER
+  && overlaps_hard_reg_set_p (regs_invalidated_by_call,
+  GET_MODE (reg), REGNO (reg)))
+ || MEM_P (reg)
+ || find_reg_fusage (call, CLOBBER, reg)))
 return true;
 
   return set_of (reg, insn) != NULL_RTX;
@@ -2165,7 +2168,7 @@ find_constant_src (const rtx_insn *insn)
in the CALL_INSN_FUNCTION_USAGE information of INSN.  */
 
 int
-find_reg_fusage (const_rtx insn, enum rtx_code code, const_rtx datum)
+find_reg_fusage (const rtx_insn *insn, enum rtx_code code, const_rtx datum)
 {
   /* If it's not a CALL_INSN, it can't possibly have a
  CALL_INSN_FUNCTION_USAGE field, so don't bother checking.  */
@@ -2210,7 +2213,7 @@ find_reg_fusage (const_rtx insn, enum rtx_code code, 
const_rtx datum)
in the CALL_INSN_FUNCTION_USAGE information of INSN.  */
 
 int
-find_regno_fusage (const_rtx insn, enum rtx_code code, unsigned int regno)
+find_regno_fusage (const rtx_insn *insn, enum rtx_code code, unsigned int 
regno)
 {
   rtx link;
 
-- 
2.9.3.dirty



[PATCH 10/11] make dead_or_set_{,regno_}p take rtx_insn *

2016-11-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-11-14  Trevor Saunders  

* rtl.h: Adjust prototype.
* rtlanal.c (dead_or_set_p): Change argument type to rtx_insn *.
(dead_or_set_regno_p): Likewise.
---
 gcc/rtl.h | 4 ++--
 gcc/rtlanal.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/rtl.h b/gcc/rtl.h
index efb8127..03c1157 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -3007,8 +3007,8 @@ extern void find_all_hard_regs (const_rtx, HARD_REG_SET 
*);
 extern void find_all_hard_reg_sets (const rtx_insn *, HARD_REG_SET *, bool);
 extern void note_stores (const_rtx, void (*) (rtx, const_rtx, void *), void *);
 extern void note_uses (rtx *, void (*) (rtx *, void *), void *);
-extern int dead_or_set_p (const_rtx, const_rtx);
-extern int dead_or_set_regno_p (const_rtx, unsigned int);
+extern int dead_or_set_p (const rtx_insn *, const_rtx);
+extern int dead_or_set_regno_p (const rtx_insn *, unsigned int);
 extern rtx find_reg_note (const_rtx, enum reg_note, const_rtx);
 extern rtx find_regno_note (const_rtx, enum reg_note, unsigned int);
 extern rtx find_reg_equal_equiv_note (const rtx_insn *);
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index 75dde3d..9cd24bb 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -1943,7 +1943,7 @@ note_uses (rtx *pbody, void (*fun) (rtx *, void *), void 
*data)
by INSN.  */
 
 int
-dead_or_set_p (const_rtx insn, const_rtx x)
+dead_or_set_p (const rtx_insn *insn, const_rtx x)
 {
   unsigned int regno, end_regno;
   unsigned int i;
@@ -2017,7 +2017,7 @@ covers_regno_p (const_rtx dest, unsigned int test_regno)
 /* Utility function for dead_or_set_p to check an individual register. */
 
 int
-dead_or_set_regno_p (const_rtx insn, unsigned int test_regno)
+dead_or_set_regno_p (const rtx_insn *insn, unsigned int test_regno)
 {
   const_rtx pattern;
 
-- 
2.9.3.dirty



[PATCH 06/11] make delete_insn () take a rtx_insn *

2016-11-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-11-14  Trevor Saunders  

* cfgrtl.c (delete_insn): Change argument type to rtx_insn *.
(fixup_reorder_chain): Adjust.
* cfgrtl.h: Adjust prototype.
---
 gcc/cfgrtl.c | 5 ++---
 gcc/cfgrtl.h | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index d2719db..d0aac09 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -123,9 +123,8 @@ can_delete_label_p (const rtx_code_label *label)
 /* Delete INSN by patching it out.  */
 
 void
-delete_insn (rtx uncast_insn)
+delete_insn (rtx_insn *insn)
 {
-  rtx_insn *insn = as_a  (uncast_insn);
   rtx note;
   bool really_delete = true;
 
@@ -3817,7 +3816,7 @@ fixup_reorder_chain (void)
  update_br_prob_note (bb);
  if (LABEL_NUSES (ret_label) == 0
  && single_pred_p (e_taken->dest))
-   delete_insn (ret_label);
+   delete_insn (as_a (ret_label));
  continue;
}
}
diff --git a/gcc/cfgrtl.h b/gcc/cfgrtl.h
index f4c1396..8e2c13c 100644
--- a/gcc/cfgrtl.h
+++ b/gcc/cfgrtl.h
@@ -20,7 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_CFGRTL_H
 #define GCC_CFGRTL_H
 
-extern void delete_insn (rtx);
+extern void delete_insn (rtx_insn *);
 extern bool delete_insn_and_edges (rtx_insn *);
 extern void delete_insn_chain (rtx, rtx_insn *, bool);
 extern basic_block create_basic_block_structure (rtx_insn *, rtx_insn *,
-- 
2.9.3.dirty



[PATCH 05/11] make replace_label_in_insn take labels as rtx_insn *

2016-11-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-11-14  Trevor Saunders  

* rtl.h: Adjust prototype.
* rtlanal.c (replace_label_in_insn): Change argument type to
rtx_insn *.
---
 gcc/rtl.h | 2 +-
 gcc/rtlanal.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/rtl.h b/gcc/rtl.h
index dc308f2..c6c30b5 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -3039,7 +3039,7 @@ extern void copy_reg_eh_region_note_backward (rtx, 
rtx_insn *, rtx);
 extern int inequality_comparisons_p (const_rtx);
 extern rtx replace_rtx (rtx, rtx, rtx, bool = false);
 extern void replace_label (rtx *, rtx, rtx, bool);
-extern void replace_label_in_insn (rtx_insn *, rtx, rtx, bool);
+extern void replace_label_in_insn (rtx_insn *, rtx_insn *, rtx_insn *, bool);
 extern bool rtx_referenced_p (const_rtx, const_rtx);
 extern bool tablejump_p (const rtx_insn *, rtx_insn **, rtx_jump_table_data 
**);
 extern int computed_jump_p (const rtx_insn *);
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index 7a89c03..504b265 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -3079,8 +3079,8 @@ replace_label (rtx *loc, rtx old_label, rtx new_label, 
bool update_label_nuses)
 }
 
 void
-replace_label_in_insn (rtx_insn *insn, rtx old_label, rtx new_label,
-  bool update_label_nuses)
+replace_label_in_insn (rtx_insn *insn, rtx_insn *old_label,
+  rtx_insn *new_label, bool update_label_nuses)
 {
   rtx insn_as_rtx = insn;
   replace_label (_as_rtx, old_label, new_label, update_label_nuses);
-- 
2.9.3.dirty



[PATCH 01/11] use rtx_insn * more places where it is obvious

2016-11-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-11-14  Trevor Saunders  

* config/arm/arm.c (legitimize_pic_address): Change to use
rtx_insn * as the type of variables.
(arm_pic_static_addr): Likewise.
(arm_emit_movpair): Likewise.
* config/c6x/c6x.c (reorg_split_calls): Likewise.
* config/darwin.c (machopic_legitimize_pic_address): Likewise.
* config/frv/frv.c (frv_optimize_membar_local): Likewise.
* config/frv/frv.md: Likewise.
* config/i386/i386-protos.h: Likewise.
* config/i386/i386.c (ix86_expand_split_stack_prologue):
Likewise.
(ix86_split_fp_branch): Likewise.
(predict_jump): Likewise.
* config/ia64/ia64.c: Likewise.
* config/mcore/mcore.c: Likewise.
* config/rs6000/rs6000.c (rs6000_legitimize_tls_address):
Likewise.
* config/s390/s390.c: Likewise.
* config/s390/s390.md: Likewise.
* config/spu/spu.md: Likewise.
* config/tilegx/tilegx.c (tilegx_legitimize_tls_address):
Likewise.
* lower-subreg.c (resolve_simple_move): Likewise.
---
 gcc/config/arm/arm.c  | 18 +++---
 gcc/config/c6x/c6x.c  |  5 +++--
 gcc/config/darwin.c   |  3 +--
 gcc/config/frv/frv.c  |  4 ++--
 gcc/config/frv/frv.md | 20 
 gcc/config/i386/i386-protos.h |  6 +++---
 gcc/config/i386/i386.c| 14 +++---
 gcc/config/ia64/ia64.c|  2 +-
 gcc/config/mcore/mcore.c  |  2 +-
 gcc/config/rs6000/rs6000.c|  4 ++--
 gcc/config/s390/s390.c|  2 +-
 gcc/config/s390/s390.md   | 21 ++---
 gcc/config/spu/spu.md |  6 +++---
 gcc/config/tilegx/tilegx.c|  3 ++-
 gcc/lower-subreg.c|  2 +-
 15 files changed, 56 insertions(+), 56 deletions(-)

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 239117f..c2bc833 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -252,7 +252,7 @@ static bool arm_can_eliminate (const int, const int);
 static void arm_asm_trampoline_template (FILE *);
 static void arm_trampoline_init (rtx, tree, rtx);
 static rtx arm_trampoline_adjust_address (rtx);
-static rtx arm_pic_static_addr (rtx orig, rtx reg);
+static rtx_insn *arm_pic_static_addr (rtx orig, rtx reg);
 static bool cortex_a9_sched_adjust_cost (rtx_insn *, int, rtx_insn *, int *);
 static bool xscale_sched_adjust_cost (rtx_insn *, int, rtx_insn *, int *);
 static bool fa726te_sched_adjust_cost (rtx_insn *, int, rtx_insn *, int *);
@@ -6903,8 +6903,6 @@ legitimize_pic_address (rtx orig, machine_mode mode, rtx 
reg)
   if (GET_CODE (orig) == SYMBOL_REF
   || GET_CODE (orig) == LABEL_REF)
 {
-  rtx insn;
-
   if (reg == 0)
{
  gcc_assert (can_create_pseudo_p ());
@@ -6917,6 +6915,7 @@ legitimize_pic_address (rtx orig, machine_mode mode, rtx 
reg)
 same segment as the GOT.  Unfortunately, the flexibility of linker
 scripts means that we can't be sure of that in general, so assume
 that GOTOFF is never valid on VxWorks.  */
+  rtx_insn *insn;
   if ((GET_CODE (orig) == LABEL_REF
   || (GET_CODE (orig) == SYMBOL_REF &&
   SYMBOL_REF_LOCAL_P (orig)))
@@ -7155,10 +7154,10 @@ arm_load_pic_register (unsigned long saved_regs 
ATTRIBUTE_UNUSED)
 }
 
 /* Generate code to load the address of a static var when flag_pic is set.  */
-static rtx
+static rtx_insn *
 arm_pic_static_addr (rtx orig, rtx reg)
 {
-  rtx l1, labelno, offset_rtx, insn;
+  rtx l1, labelno, offset_rtx;
 
   gcc_assert (flag_pic);
 
@@ -7175,8 +7174,7 @@ arm_pic_static_addr (rtx orig, rtx reg)
UNSPEC_SYMBOL_OFFSET);
   offset_rtx = gen_rtx_CONST (Pmode, offset_rtx);
 
-  insn = emit_insn (gen_pic_load_addr_unified (reg, offset_rtx, labelno));
-  return insn;
+  return emit_insn (gen_pic_load_addr_unified (reg, offset_rtx, labelno));
 }
 
 /* Return nonzero if X is valid as an ARM state addressing register.  */
@@ -16928,8 +16926,6 @@ output_mov_long_double_arm_from_arm (rtx *operands)
 void
 arm_emit_movpair (rtx dest, rtx src)
  {
-  rtx insn;
-
   /* If the src is an immediate, simplify it.  */
   if (CONST_INT_P (src))
 {
@@ -16940,14 +16936,14 @@ arm_emit_movpair (rtx dest, rtx src)
  emit_set_insn (gen_rtx_ZERO_EXTRACT (SImode, dest, GEN_INT (16),
   GEN_INT (16)),
 GEN_INT ((val >> 16) & 0x));
- insn = get_last_insn ();
+ rtx_insn *insn = get_last_insn ();
  set_unique_reg_note (insn, REG_EQUAL, copy_rtx (src));
}
   return;
 }
emit_set_insn (dest, gen_rtx_HIGH (SImode, src));
emit_set_insn (dest, gen_rtx_LO_SUM (SImode, dest, src));
-   insn = get_last_insn ();
+   rtx_insn *insn = get_last_insn ();
set_unique_reg_note (insn, REG_EQUAL, copy_rtx (src));
  }
 
diff --git 

[PATCH 02/11] split up variables to use rtx_insn * more

2016-11-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-11-14  Trevor Saunders  

* config/aarch64/aarch64.c (aarch64_emit_unlikely_jump): split
up variables to make some rtx_insn *.
* config/alpha/alpha.c (emit_unlikely_jump): Likewise.
* config/arc/arc.c: Likewise.
* config/arm/arm.c: Likewise.
* config/mn10300/mn10300.c (mn10300_legitimize_pic_address):
Likewise.
* config/rs6000/rs6000.c (rs6000_expand_split_stack_prologue):
Likewise.
* config/spu/spu.c (spu_emit_branch_hint): Likewise.
---
 gcc/config/aarch64/aarch64.c |  4 ++--
 gcc/config/alpha/alpha.c |  8 +++-
 gcc/config/arc/arc.c |  4 ++--
 gcc/config/arm/arm.c |  4 ++--
 gcc/config/mn10300/mn10300.c |  9 +
 gcc/config/rs6000/rs6000.c   | 14 ++
 gcc/config/spu/spu.c |  7 +++
 7 files changed, 23 insertions(+), 27 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index b7d4640..b6676f1 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -11474,8 +11474,8 @@ aarch64_emit_unlikely_jump (rtx insn)
 {
   int very_unlikely = REG_BR_PROB_BASE / 100 - 1;
 
-  insn = emit_jump_insn (insn);
-  add_int_reg_note (insn, REG_BR_PROB, very_unlikely);
+  rtx_insn *jump = emit_jump_insn (insn);
+  add_int_reg_note (jump, REG_BR_PROB, very_unlikely);
 }
 
 /* Expand a compare and swap pattern.  */
diff --git a/gcc/config/alpha/alpha.c b/gcc/config/alpha/alpha.c
index 6d390ae..6c63a8f 100644
--- a/gcc/config/alpha/alpha.c
+++ b/gcc/config/alpha/alpha.c
@@ -4320,11 +4320,9 @@ static void
 emit_unlikely_jump (rtx cond, rtx label)
 {
   int very_unlikely = REG_BR_PROB_BASE / 100 - 1;
-  rtx x;
-
-  x = gen_rtx_IF_THEN_ELSE (VOIDmode, cond, label, pc_rtx);
-  x = emit_jump_insn (gen_rtx_SET (pc_rtx, x));
-  add_int_reg_note (x, REG_BR_PROB, very_unlikely);
+  rtx x = gen_rtx_IF_THEN_ELSE (VOIDmode, cond, label, pc_rtx);
+  rtx_insn *insn = emit_jump_insn (gen_rtx_SET (pc_rtx, x));
+  add_int_reg_note (insn, REG_BR_PROB, very_unlikely);
 }
 
 /* A subroutine of the atomic operation splitters.  Emit a load-locked
diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index 5ba7ccc..dbaad24 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -9523,8 +9523,8 @@ emit_unlikely_jump (rtx insn)
 {
   int very_unlikely = REG_BR_PROB_BASE / 100 - 1;
 
-  insn = emit_jump_insn (insn);
-  add_int_reg_note (insn, REG_BR_PROB, very_unlikely);
+  rtx_insn *jump = emit_jump_insn (insn);
+  add_int_reg_note (jump, REG_BR_PROB, very_unlikely);
 }
 
 /* Expand code to perform a 8 or 16-bit compare and swap by doing
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index c2bc833..3e63330 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -26931,8 +26931,8 @@ emit_unlikely_jump (rtx insn)
 {
   int very_unlikely = REG_BR_PROB_BASE / 100 - 1;
 
-  insn = emit_jump_insn (insn);
-  add_int_reg_note (insn, REG_BR_PROB, very_unlikely);
+  rtx_insn *jump = emit_jump_insn (insn);
+  add_int_reg_note (jump, REG_BR_PROB, very_unlikely);
 }
 
 /* Expand a compare and swap pattern.  */
diff --git a/gcc/config/mn10300/mn10300.c b/gcc/config/mn10300/mn10300.c
index e61bf40..cfc8604 100644
--- a/gcc/config/mn10300/mn10300.c
+++ b/gcc/config/mn10300/mn10300.c
@@ -1860,6 +1860,7 @@ rtx
 mn10300_legitimize_pic_address (rtx orig, rtx reg)
 {
   rtx x;
+  rtx_insn *insn;
 
   if (GET_CODE (orig) == LABEL_REF
   || (GET_CODE (orig) == SYMBOL_REF
@@ -1873,7 +1874,7 @@ mn10300_legitimize_pic_address (rtx orig, rtx reg)
   x = gen_rtx_CONST (SImode, x);
   emit_move_insn (reg, x);
 
-  x = emit_insn (gen_addsi3 (reg, reg, pic_offset_table_rtx));
+  insn = emit_insn (gen_addsi3 (reg, reg, pic_offset_table_rtx));
 }
   else if (GET_CODE (orig) == SYMBOL_REF)
 {
@@ -1885,12 +1886,12 @@ mn10300_legitimize_pic_address (rtx orig, rtx reg)
   x = gen_rtx_PLUS (SImode, pic_offset_table_rtx, x);
   x = gen_const_mem (SImode, x);
 
-  x = emit_move_insn (reg, x);
+  insn = emit_move_insn (reg, x);
 }
   else
 return orig;
 
-  set_unique_reg_note (x, REG_EQUAL, orig);
+  set_unique_reg_note (insn, REG_EQUAL, orig);
   return reg;
 }
 
@@ -3163,7 +3164,7 @@ mn10300_bundle_liw (void)
Insert a SETLB insn just before LABEL.  */
 
 static void
-mn10300_insert_setlb_lcc (rtx_insn *label, rtx branch)
+mn10300_insert_setlb_lcc (rtx_insn *label, rtx_insn *branch)
 {
   rtx lcc, comparison, cmp_reg;
 
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 0e05500..297df64 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -24641,11 +24641,9 @@ static void
 emit_unlikely_jump (rtx cond, rtx label)
 {
   int very_unlikely = REG_BR_PROB_BASE / 100 - 1;
-  rtx x;
-
-  x = gen_rtx_IF_THEN_ELSE (VOIDmode, cond, label, pc_rtx);
-  x = emit_jump_insn (gen_rtx_SET 

[PATCH 03/11] make find_reg_equal_equiv_note take rtx_insn *

2016-11-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-11-14  Trevor Saunders  

* cse.c (count_reg_usage): Adjust.
* rtl.h: Adjust prototypes.
* rtlanal.c (find_reg_equal_equiv_note): Change argument type to
rtx_insn *.
---
 gcc/cse.c | 63 +++
 gcc/rtl.h |  2 +-
 gcc/rtlanal.c |  2 +-
 3 files changed, 35 insertions(+), 32 deletions(-)

diff --git a/gcc/cse.c b/gcc/cse.c
index 11b8fbe..a2d8b4f 100644
--- a/gcc/cse.c
+++ b/gcc/cse.c
@@ -6824,37 +6824,40 @@ count_reg_usage (rtx x, int *counts, rtx dest, int incr)
 case CALL_INSN:
 case INSN:
 case JUMP_INSN:
-  /* We expect dest to be NULL_RTX here.  If the insn may throw,
-or if it cannot be deleted due to side-effects, mark this fact
-by setting DEST to pc_rtx.  */
-  if ((!cfun->can_delete_dead_exceptions && !insn_nothrow_p (x))
- || side_effects_p (PATTERN (x)))
-   dest = pc_rtx;
-  if (code == CALL_INSN)
-   count_reg_usage (CALL_INSN_FUNCTION_USAGE (x), counts, dest, incr);
-  count_reg_usage (PATTERN (x), counts, dest, incr);
-
-  /* Things used in a REG_EQUAL note aren't dead since loop may try to
-use them.  */
-
-  note = find_reg_equal_equiv_note (x);
-  if (note)
-   {
- rtx eqv = XEXP (note, 0);
+  {
+   rtx_insn *insn = as_a (x);
+   /* We expect dest to be NULL_RTX here.  If the insn may throw,
+  or if it cannot be deleted due to side-effects, mark this fact
+  by setting DEST to pc_rtx.  */
+   if ((!cfun->can_delete_dead_exceptions && !insn_nothrow_p (x))
+   || side_effects_p (PATTERN (x)))
+ dest = pc_rtx;
+   if (code == CALL_INSN)
+ count_reg_usage (CALL_INSN_FUNCTION_USAGE (x), counts, dest, incr);
+   count_reg_usage (PATTERN (x), counts, dest, incr);
+
+   /* Things used in a REG_EQUAL note aren't dead since loop may try to
+  use them.  */
+
+   note = find_reg_equal_equiv_note (insn);
+   if (note)
+ {
+   rtx eqv = XEXP (note, 0);
 
- if (GET_CODE (eqv) == EXPR_LIST)
- /* This REG_EQUAL note describes the result of a function call.
-Process all the arguments.  */
-   do
- {
-   count_reg_usage (XEXP (eqv, 0), counts, dest, incr);
-   eqv = XEXP (eqv, 1);
- }
-   while (eqv && GET_CODE (eqv) == EXPR_LIST);
- else
-   count_reg_usage (eqv, counts, dest, incr);
-   }
-  return;
+   if (GET_CODE (eqv) == EXPR_LIST)
+ /* This REG_EQUAL note describes the result of a function call.
+Process all the arguments.  */
+ do
+   {
+ count_reg_usage (XEXP (eqv, 0), counts, dest, incr);
+ eqv = XEXP (eqv, 1);
+   }
+ while (eqv && GET_CODE (eqv) == EXPR_LIST);
+   else
+ count_reg_usage (eqv, counts, dest, incr);
+ }
+   return;
+  }
 
 case EXPR_LIST:
   if (REG_NOTE_KIND (x) == REG_EQUAL
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 7a44e3b..dc308f2 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -3011,7 +3011,7 @@ extern int dead_or_set_p (const_rtx, const_rtx);
 extern int dead_or_set_regno_p (const_rtx, unsigned int);
 extern rtx find_reg_note (const_rtx, enum reg_note, const_rtx);
 extern rtx find_regno_note (const_rtx, enum reg_note, unsigned int);
-extern rtx find_reg_equal_equiv_note (const_rtx);
+extern rtx find_reg_equal_equiv_note (const rtx_insn *);
 extern rtx find_constant_src (const rtx_insn *);
 extern int find_reg_fusage (const_rtx, enum rtx_code, const_rtx);
 extern int find_regno_fusage (const_rtx, enum rtx_code, unsigned int);
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index 4617e8e..7a89c03 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -2113,7 +2113,7 @@ find_regno_note (const_rtx insn, enum reg_note kind, 
unsigned int regno)
has such a note.  */
 
 rtx
-find_reg_equal_equiv_note (const_rtx insn)
+find_reg_equal_equiv_note (const rtx_insn *insn)
 {
   rtx link;
 
-- 
2.9.3.dirty



[PATCH 00/11] more rtx_insn * stuff

2016-11-14 Thread tbsaunde+gcc
From: Trevor Saunders 

Hi,

Basically $subject which gets rid of a few more casts over all.

I ment to get this out a little while back, but life got busy, and I didn't
read the status announcement properly, so virtually working from hawaii for
now. patches individually built and regtested on x86_64-linux-gnu, and series
run through config-list.mk, ok?

Thanks!

Trev

Trevor Saunders (11):
  use rtx_insn * more places where it is obvious
  split up variables to use rtx_insn * more
  make find_reg_equal_equiv_note take rtx_insn *
  make recog () take a rtx_insn *
  make replace_label_in_insn take labels as rtx_insn *
  make delete_insn () take a rtx_insn *
  remove cast from emit_libcall_block
  make prologue_epilogue_contains take a rtx_insn *
  make add_int_reg_note take rtx_insn *
  make dead_or_set_{,regno_}p take rtx_insn *
  make find_reg{,no}_fusage take rtx_insn *

 gcc/cfgrtl.c  |  5 ++--
 gcc/cfgrtl.h  |  2 +-
 gcc/config/aarch64/aarch64.c  |  4 +--
 gcc/config/alpha/alpha.c  |  8 +++---
 gcc/config/arc/arc.c  |  4 +--
 gcc/config/arm/arm-protos.h   |  2 +-
 gcc/config/arm/arm.c  | 24 +++--
 gcc/config/c6x/c6x.c  |  5 ++--
 gcc/config/darwin.c   |  3 +--
 gcc/config/frv/frv.c  |  4 +--
 gcc/config/frv/frv.md | 20 ++
 gcc/config/i386/i386-protos.h |  6 ++---
 gcc/config/i386/i386.c| 14 +-
 gcc/config/ia64/ia64.c|  2 +-
 gcc/config/mcore/mcore.c  |  2 +-
 gcc/config/mn10300/mn10300.c  |  9 ---
 gcc/config/rs6000/rs6000.c| 18 ++---
 gcc/config/s390/s390.c|  2 +-
 gcc/config/s390/s390.md   | 21 ++-
 gcc/config/spu/spu.c  |  7 +++--
 gcc/config/spu/spu.md |  6 ++---
 gcc/config/tilegx/tilegx.c|  3 ++-
 gcc/config/v850/v850.c|  4 +--
 gcc/cse.c | 63 ++-
 gcc/expr.c|  4 +--
 gcc/function.c| 12 -
 gcc/function.h|  6 ++---
 gcc/genrecog.c|  8 +-
 gcc/lower-subreg.c|  2 +-
 gcc/optabs.c  |  5 ++--
 gcc/optabs.h  |  2 +-
 gcc/recog.h   |  2 +-
 gcc/rtl.h | 22 ++-
 gcc/rtlanal.c | 35 +---
 34 files changed, 169 insertions(+), 167 deletions(-)

-- 
2.9.3.dirty



[PATCH 04/11] make recog () take a rtx_insn *

2016-11-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-11-14  Trevor Saunders  

* config/v850/v850.c (expand_prologue): Adjust.
(expand_epilogue): Likewise.
* expr.c (init_expr_target): Likewise.
* genrecog.c (print_subroutine): Always make the argument type
rtx_insn *.
* recog.h: Adjust prototype.
---
 gcc/config/v850/v850.c | 4 ++--
 gcc/expr.c | 4 ++--
 gcc/genrecog.c | 8 +---
 gcc/recog.h| 2 +-
 4 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/gcc/config/v850/v850.c b/gcc/config/v850/v850.c
index 91e182f..c27bb6d 100644
--- a/gcc/config/v850/v850.c
+++ b/gcc/config/v850/v850.c
@@ -1741,7 +1741,7 @@ expand_prologue (void)
 
  v850_all_frame_related (save_all);
 
- code = recog (save_all, NULL_RTX, NULL);
+ code = recog (save_all, NULL, NULL);
  if (code >= 0)
{
  rtx insn = emit_insn (save_all);
@@ -1887,7 +1887,7 @@ expand_epilogue (void)
  offset -= 4;
}
 
- code = recog (restore_all, NULL_RTX, NULL);
+ code = recog (restore_all, NULL, NULL);
  
  if (code >= 0)
{
diff --git a/gcc/expr.c b/gcc/expr.c
index 0b0946d..5d19699 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -109,7 +109,7 @@ static HOST_WIDE_INT int_expr_size (tree);
 void
 init_expr_target (void)
 {
-  rtx insn, pat;
+  rtx pat;
   machine_mode mode;
   int num_clobbers;
   rtx mem, mem1;
@@ -125,7 +125,7 @@ init_expr_target (void)
  useless RTL allocations.  */
   reg = gen_rtx_REG (word_mode, LAST_VIRTUAL_REGISTER + 1);
 
-  insn = rtx_alloc (INSN);
+  rtx_insn *insn = as_a (rtx_alloc (INSN));
   pat = gen_rtx_SET (NULL_RTX, NULL_RTX);
   PATTERN (insn) = pat;
 
diff --git a/gcc/genrecog.c b/gcc/genrecog.c
index a8e8c22..aa7f629 100644
--- a/gcc/genrecog.c
+++ b/gcc/genrecog.c
@@ -5102,8 +5102,7 @@ print_subroutine (output_state *os, state *s, int proc_id)
   /* For now, the top-level "recog" takes a plain "rtx", and performs a
  checked cast to "rtx_insn *" for use throughout the rest of the
  function and the code it calls.  */
-  const char *insn_param
-= proc_id > 0 ? "rtx_insn *insn" : "rtx uncast_insn";
+  const char *insn_param = "rtx_insn *insn";
   printf ("\n");
   switch (os->type)
 {
@@ -5142,11 +5141,6 @@ print_subroutine (output_state *os, state *s, int 
proc_id)
   if (proc_id == 0)
 {
   printf ("  recog_data.insn = NULL;\n");
-  if (os->type == RECOG)
-   {
- printf ("  rtx_insn *insn ATTRIBUTE_UNUSED;\n");
- printf ("  insn = safe_as_a  (uncast_insn);\n");
-   }
 }
   print_state (os, s, 2, true);
   printf ("}\n");
diff --git a/gcc/recog.h b/gcc/recog.h
index 3a59af8..9f6c42c 100644
--- a/gcc/recog.h
+++ b/gcc/recog.h
@@ -124,7 +124,7 @@ extern int offsettable_address_addr_space_p (int, 
machine_mode, rtx,
  ADDR_SPACE_GENERIC)
 extern bool mode_dependent_address_p (rtx, addr_space_t);
 
-extern int recog (rtx, rtx, int *);
+extern int recog (rtx, rtx_insn *, int *);
 #ifndef GENERATOR_FILE
 static inline int recog_memoized (rtx_insn *insn);
 #endif
-- 
2.9.3.dirty



[PATCH] add a gimple test for PR21458

2016-10-31 Thread tbsaunde+gcc
From: Trevor Saunders 

A demonstration we can do the same thing with a gimple test as -fno-tree-evrp 
but somewhat more precisely.

I tested this passes on x86_64-linux-gnu, ok?

Trev

gcc/testsuite/ChangeLog:

2016-10-31  Trevor Saunders  

* gcc.dg/tree-ssa/pr21458-3.c: New test.
---
 gcc/testsuite/gcc.dg/tree-ssa/pr21458-3.c | 40 +++
 1 file changed, 40 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr21458-3.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr21458-3.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr21458-3.c
new file mode 100644
index 000..6433a7e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr21458-3.c
@@ -0,0 +1,40 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fgimple -fdump-tree-vrp1" } */
+
+extern void g (void);
+extern void bar (int);
+
+int __GIMPLE(startwith("vrp1"))
+foo (int a)
+{
+int i;
+
+  bb_2:
+  i_4 = 1;
+goto bb_6;
+
+ bb_3:
+ if (i_1 != 0)
+   goto bb_4;
+   else
+ goto bb_5;
+
+ bb_4:
+ g ();
+
+   bb_5:
+   i_7 = i_1 + 1;
+
+ bb_6:
+ i_1 = __PHI (bb_2: i_4, bb_5: i_7);
+   if (i_1 <= 99)
+ goto bb_3;
+ else
+   goto bb_7;
+
+   bb_7:
+   return;
+
+}
+
+/* { dg-final { scan-tree-dump-times "Folding predicate.*to 1" 1 "vrp1" } } */
-- 
2.9.3.dirty



[PATCH 1/3] use rtx_insn * in various places where it is obvious

2016-10-28 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-10-27  Trevor Saunders  

* config/arc/arc.c (arc_emit_call_tls_get_addr): Make the type
of variables rtx_insn *.
* config/arm/arm.c (arm_call_tls_get_addr): Likewise.
(legitimize_tls_address): Likewise.
* config/bfin/bfin.c (hwloop_optimize): Likewise.
(bfin_gen_bundles): Likewise.
* config/c6x/c6x.c (reorg_split_calls): Likewise.
(c6x_reorg): Likewise.
* config/frv/frv.c (frv_reorder_packet): Likewise.
* config/i386/i386.c (ix86_split_idivmod): Likewise.
* config/ia64/ia64.c (ia64_expand_compare): Likewise.
* config/m32c/m32c.c (m32c_prepare_shift): Likewise.
* config/mn10300/mn10300.c: Likewise.
* config/rl78/rl78.c: Likewise.
* config/s390/s390.c (s390_fix_long_loop_prediction): Likewise.
* config/sh/sh-mem.cc (sh_expand_cmpstr): Likewise.
(sh_expand_cmpnstr): Likewise.
(sh_expand_strlen): Likewise.
(sh_expand_setmem): Likewise.
* config/sh/sh.md: Likewise.
* emit-rtl.c (emit_pattern_before): Likewise.
* except.c: Likewise.
* final.c: Likewise.
* jump.c: Likewise.
---
 gcc/config/arc/arc.c |  3 +--
 gcc/config/arm/arm.c |  9 +
 gcc/config/bfin/bfin.c   |  7 ---
 gcc/config/c6x/c6x.c |  9 -
 gcc/config/frv/frv.c |  2 +-
 gcc/config/i386/i386.c   |  3 ++-
 gcc/config/ia64/ia64.c   |  4 ++--
 gcc/config/m32c/m32c.c   |  4 ++--
 gcc/config/mn10300/mn10300.c |  2 +-
 gcc/config/rl78/rl78.c   |  2 +-
 gcc/config/s390/s390.c   |  7 ---
 gcc/config/sh/sh-mem.cc  |  8 
 gcc/config/sh/sh.md  | 18 +-
 gcc/emit-rtl.c   |  2 +-
 gcc/except.c |  2 +-
 gcc/final.c  |  4 ++--
 gcc/jump.c   |  4 ++--
 17 files changed, 46 insertions(+), 44 deletions(-)

diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index 21bba0c..8e8fff4 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -4829,7 +4829,6 @@ static rtx
 arc_emit_call_tls_get_addr (rtx sym, int reloc, rtx eqv)
 {
   rtx r0 = gen_rtx_REG (Pmode, R0_REG);
-  rtx insns;
   rtx call_fusage = NULL_RTX;
 
   start_sequence ();
@@ -4846,7 +4845,7 @@ arc_emit_call_tls_get_addr (rtx sym, int reloc, rtx eqv)
   RTL_PURE_CALL_P (call_insn) = 1;
   add_function_usage_to (call_insn, call_fusage);
 
-  insns = get_insns ();
+  rtx_insn *insns = get_insns ();
   end_sequence ();
 
   rtx dest = gen_reg_rtx (Pmode);
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 022c1d7..6351987 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -7900,10 +7900,10 @@ load_tls_operand (rtx x, rtx reg)
   return reg;
 }
 
-static rtx
+static rtx_insn *
 arm_call_tls_get_addr (rtx x, rtx reg, rtx *valuep, int reloc)
 {
-  rtx insns, label, labelno, sum;
+  rtx label, labelno, sum;
 
   gcc_assert (reloc != TLS_DESCSEQ);
   start_sequence ();
@@ -7927,7 +7927,7 @@ arm_call_tls_get_addr (rtx x, rtx reg, rtx *valuep, int 
reloc)
 LCT_PURE, /* LCT_CONST?  */
 Pmode, 1, reg, Pmode);
 
-  insns = get_insns ();
+  rtx_insn *insns = get_insns ();
   end_sequence ();
 
   return insns;
@@ -7959,7 +7959,8 @@ arm_tls_descseq_addr (rtx x, rtx reg)
 rtx
 legitimize_tls_address (rtx x, rtx reg)
 {
-  rtx dest, tp, label, labelno, sum, insns, ret, eqv, addend;
+  rtx dest, tp, label, labelno, sum, ret, eqv, addend;
+  rtx_insn *insns;
   unsigned int model = SYMBOL_REF_TLS_MODEL (x);
 
   switch (model)
diff --git a/gcc/config/bfin/bfin.c b/gcc/config/bfin/bfin.c
index 9b81868..957f1ae 100644
--- a/gcc/config/bfin/bfin.c
+++ b/gcc/config/bfin/bfin.c
@@ -3431,7 +3431,8 @@ hwloop_optimize (hwloop_info loop)
   basic_block bb;
   rtx_insn *insn, *last_insn;
   rtx loop_init, start_label, end_label;
-  rtx iter_reg, scratchreg, scratch_init, scratch_init_insn;
+  rtx iter_reg, scratchreg, scratch_init;
+  rtx_insn *scratch_init_insn;
   rtx lc_reg, lt_reg, lb_reg;
   rtx seq_end;
   rtx_insn *seq;
@@ -3452,7 +3453,7 @@ hwloop_optimize (hwloop_info loop)
 
   scratchreg = NULL_RTX;
   scratch_init = iter_reg;
-  scratch_init_insn = NULL_RTX;
+  scratch_init_insn = NULL;
   if (!PREG_P (iter_reg) && loop->incoming_src)
 {
   basic_block bb_in = loop->incoming_src;
@@ -3976,7 +3977,7 @@ bfin_gen_bundles (void)
   for (insn = BB_HEAD (bb);; insn = next)
{
  int at_end;
- rtx delete_this = NULL_RTX;
+ rtx_insn *delete_this = NULL;
 
  if (NONDEBUG_INSN_P (insn))
{
diff --git a/gcc/config/c6x/c6x.c b/gcc/config/c6x/c6x.c
index f8c3d66..6cb9185 100644
--- a/gcc/config/c6x/c6x.c
+++ b/gcc/config/c6x/c6x.c
@@ -4856,7 +4856,7 @@ find_last_same_clock (rtx_insn *insn)
the SEQUENCEs that 

[PATCH 3/3] split up some variables to use rtx_insn * more

2016-10-28 Thread tbsaunde+gcc
From: Trevor Saunders 

Note to readers, a -b diff is below the whitespace sensitive one and should be
much easier to read.

gcc/ChangeLog:

2016-10-27  Trevor Saunders  

* config/alpha/alpha.c (alpha_legitimize_address_1): Split up
variables so some can be rtx_insn *.
(alpha_emit_xfloating_libcall): Likewise.
* config/mips/mips.c (mips_call_tls_get_addr): Likewise.
(mips_legitimize_tls_address): Likewise.
* optabs.c (expand_binop): Likewise.
* reload1.c (gen_reload): Likewise.
---
 gcc/config/alpha/alpha.c | 117 ---
 gcc/config/mips/mips.c   |  61 
 gcc/optabs.c |   5 +-
 gcc/reload1.c|   9 ++--
 4 files changed, 101 insertions(+), 91 deletions(-)

diff --git a/gcc/config/alpha/alpha.c b/gcc/config/alpha/alpha.c
index 7f53967..6d390ae 100644
--- a/gcc/config/alpha/alpha.c
+++ b/gcc/config/alpha/alpha.c
@@ -1017,7 +1017,8 @@ alpha_legitimize_address_1 (rtx x, rtx scratch, 
machine_mode mode)
   && GET_MODE_SIZE (mode) <= UNITS_PER_WORD
   && symbolic_operand (x, Pmode))
 {
-  rtx r0, r16, eqv, tga, tp, insn, dest, seq;
+  rtx r0, r16, eqv, tga, tp, dest, seq;
+  rtx_insn *insn;
 
   switch (tls_symbolic_operand_type (x))
{
@@ -1025,66 +1026,70 @@ alpha_legitimize_address_1 (rtx x, rtx scratch, 
machine_mode mode)
  break;
 
case TLS_MODEL_GLOBAL_DYNAMIC:
- start_sequence ();
+ {
+   start_sequence ();
 
- r0 = gen_rtx_REG (Pmode, 0);
- r16 = gen_rtx_REG (Pmode, 16);
- tga = get_tls_get_addr ();
- dest = gen_reg_rtx (Pmode);
- seq = GEN_INT (alpha_next_sequence_number++);
+   r0 = gen_rtx_REG (Pmode, 0);
+   r16 = gen_rtx_REG (Pmode, 16);
+   tga = get_tls_get_addr ();
+   dest = gen_reg_rtx (Pmode);
+   seq = GEN_INT (alpha_next_sequence_number++);
 
- emit_insn (gen_movdi_er_tlsgd (r16, pic_offset_table_rtx, x, seq));
- insn = gen_call_value_osf_tlsgd (r0, tga, seq);
- insn = emit_call_insn (insn);
- RTL_CONST_CALL_P (insn) = 1;
- use_reg (_INSN_FUNCTION_USAGE (insn), r16);
+   emit_insn (gen_movdi_er_tlsgd (r16, pic_offset_table_rtx, x, seq));
+   rtx val = gen_call_value_osf_tlsgd (r0, tga, seq);
+   insn = emit_call_insn (val);
+   RTL_CONST_CALL_P (insn) = 1;
+   use_reg (_INSN_FUNCTION_USAGE (insn), r16);
 
-  insn = get_insns ();
- end_sequence ();
+   insn = get_insns ();
+   end_sequence ();
 
- emit_libcall_block (insn, dest, r0, x);
- return dest;
+   emit_libcall_block (insn, dest, r0, x);
+   return dest;
+ }
 
case TLS_MODEL_LOCAL_DYNAMIC:
- start_sequence ();
+ {
+   start_sequence ();
 
- r0 = gen_rtx_REG (Pmode, 0);
- r16 = gen_rtx_REG (Pmode, 16);
- tga = get_tls_get_addr ();
- scratch = gen_reg_rtx (Pmode);
- seq = GEN_INT (alpha_next_sequence_number++);
+   r0 = gen_rtx_REG (Pmode, 0);
+   r16 = gen_rtx_REG (Pmode, 16);
+   tga = get_tls_get_addr ();
+   scratch = gen_reg_rtx (Pmode);
+   seq = GEN_INT (alpha_next_sequence_number++);
 
- emit_insn (gen_movdi_er_tlsldm (r16, pic_offset_table_rtx, seq));
- insn = gen_call_value_osf_tlsldm (r0, tga, seq);
- insn = emit_call_insn (insn);
- RTL_CONST_CALL_P (insn) = 1;
- use_reg (_INSN_FUNCTION_USAGE (insn), r16);
+   emit_insn (gen_movdi_er_tlsldm (r16, pic_offset_table_rtx, seq));
+   rtx val = gen_call_value_osf_tlsldm (r0, tga, seq);
+   insn = emit_call_insn (val);
+   RTL_CONST_CALL_P (insn) = 1;
+   use_reg (_INSN_FUNCTION_USAGE (insn), r16);
 
-  insn = get_insns ();
- end_sequence ();
+   insn = get_insns ();
+   end_sequence ();
 
- eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
-   UNSPEC_TLSLDM_CALL);
- emit_libcall_block (insn, scratch, r0, eqv);
+   eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
+ UNSPEC_TLSLDM_CALL);
+   emit_libcall_block (insn, scratch, r0, eqv);
 
- eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPREL);
- eqv = gen_rtx_CONST (Pmode, eqv);
+   eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPREL);
+   eqv = gen_rtx_CONST (Pmode, eqv);
 
- if (alpha_tls_size == 64)
-   {
- dest = gen_reg_rtx (Pmode);
- emit_insn (gen_rtx_SET (dest, eqv));
- emit_insn (gen_adddi3 (dest, dest, scratch));
- return dest;
-   }
- if (alpha_tls_size == 32)
-   {
- 

[PATCH 0/3] use rtx_insn * more

2016-10-28 Thread tbsaunde+gcc
From: Trevor Saunders 

HI,

This series changes various variables type from rtx to rtx_insn * so that the
remaining patches in this series
http://gcc.gnu.org/ml/gcc-patches/2016-10/msg01353.html can be applied.

patches bootstrapped and regtested on x86_64-linux-gnu, and run through 
config-list.mk, ok?

Thanks!

Trev

Trevor Saunders (3):
  use rtx_insn * in various places where it is obvious
  split up the trial variable in reorg.c:relax_delay_slots to use
rtx_insn * more
  split up some variables to use rtx_insn * more

 gcc/config/alpha/alpha.c | 117 ++-
 gcc/config/arc/arc.c |   3 +-
 gcc/config/arm/arm.c |   9 ++--
 gcc/config/bfin/bfin.c   |   7 +--
 gcc/config/c6x/c6x.c |   9 ++--
 gcc/config/frv/frv.c |   2 +-
 gcc/config/i386/i386.c   |   3 +-
 gcc/config/ia64/ia64.c   |   4 +-
 gcc/config/m32c/m32c.c   |   4 +-
 gcc/config/mips/mips.c   |  61 +++---
 gcc/config/mn10300/mn10300.c |   2 +-
 gcc/config/rl78/rl78.c   |   2 +-
 gcc/config/s390/s390.c   |   7 +--
 gcc/config/sh/sh-mem.cc  |   8 +--
 gcc/config/sh/sh.md  |  18 +++
 gcc/emit-rtl.c   |   2 +-
 gcc/except.c |   2 +-
 gcc/final.c  |   4 +-
 gcc/jump.c   |   4 +-
 gcc/optabs.c |   5 +-
 gcc/reload1.c|   9 ++--
 gcc/reorg.c  |  19 ---
 22 files changed, 156 insertions(+), 145 deletions(-)

-- 
2.9.3.dirty



[PATCH 2/3] split up the trial variable in reorg.c:relax_delay_slots to use rtx_insn * more

2016-10-28 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-10-27  Trevor Saunders  

* reorg.c (relax_delay_slots): Split up the trial variable.
---
 gcc/reorg.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/gcc/reorg.c b/gcc/reorg.c
index 799d27b..da4d7c6 100644
--- a/gcc/reorg.c
+++ b/gcc/reorg.c
@@ -222,7 +222,7 @@ static void steal_delay_list_from_fallthrough (rtx_insn *, 
rtx, rtx_sequence *,
 static void try_merge_delay_insns (rtx_insn *, rtx_insn *);
 static rtx_insn *redundant_insn (rtx, rtx_insn *, const vec &);
 static int own_thread_p (rtx, rtx, int);
-static void update_block (rtx_insn *, rtx);
+static void update_block (rtx_insn *, rtx_insn *);
 static int reorg_redirect_jump (rtx_jump_insn *, rtx);
 static void update_reg_dead_notes (rtx_insn *, rtx_insn *);
 static void fix_reg_dead_note (rtx_insn *, rtx);
@@ -1703,7 +1703,7 @@ own_thread_p (rtx thread, rtx label, int 
allow_fallthrough)
BARRIER in relax_delay_slots.  */
 
 static void
-update_block (rtx_insn *insn, rtx where)
+update_block (rtx_insn *insn, rtx_insn *where)
 {
   /* Ignore if this was in a delay slot and it came from the target of
  a branch.  */
@@ -3118,7 +3118,6 @@ relax_delay_slots (rtx_insn *first)
 {
   rtx_insn *insn, *next;
   rtx_sequence *pat;
-  rtx trial;
   rtx_insn *delay_insn;
   rtx target_label;
 
@@ -3271,10 +3270,10 @@ relax_delay_slots (rtx_insn *first)
  for (i = 0; i < XVECLEN (pat, 0); i++)
INSN_FROM_TARGET_P (XVECEXP (pat, 0, i)) = 0;
 
- trial = PREV_INSN (insn);
+ rtx_insn *prev = PREV_INSN (insn);
  delete_related_insns (insn);
  gcc_assert (GET_CODE (pat) == SEQUENCE);
- add_insn_after (delay_insn, trial, NULL);
+ add_insn_after (delay_insn, prev, NULL);
  after = delay_insn;
  for (i = 1; i < pat->len (); i++)
after = emit_copy_of_insn_after (pat->insn (i), after);
@@ -3295,9 +3294,9 @@ relax_delay_slots (rtx_insn *first)
 
   /* If this jump goes to another unconditional jump, thread it, but
 don't convert a jump into a RETURN here.  */
-  trial = skip_consecutive_labels (follow_jumps (target_label,
-delay_jump_insn,
-));
+  rtx trial = skip_consecutive_labels (follow_jumps (target_label,
+delay_jump_insn,
+));
   if (ANY_RETURN_P (trial))
trial = find_end_label (trial);
 
@@ -3401,10 +3400,10 @@ relax_delay_slots (rtx_insn *first)
  for (i = 0; i < XVECLEN (pat, 0); i++)
INSN_FROM_TARGET_P (XVECEXP (pat, 0, i)) = 0;
 
- trial = PREV_INSN (insn);
+ rtx_insn *prev = PREV_INSN (insn);
  delete_related_insns (insn);
  gcc_assert (GET_CODE (pat) == SEQUENCE);
- add_insn_after (delay_jump_insn, trial, NULL);
+ add_insn_after (delay_jump_insn, prev, NULL);
  after = delay_jump_insn;
  for (i = 1; i < pat->len (); i++)
after = emit_copy_of_insn_after (pat->insn (i), after);
-- 
2.9.3.dirty



[PATCH] fix an uninitialized use of loc when parsing gimple switches

2016-10-26 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/c/ChangeLog:

2016-10-27  Trevor Saunders  

* gimple-parser.c (c_parser_gimple_switch_stmt): Fix
uninitialized use of loc.
---
 gcc/c/gimple-parser.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index e9e3aae..8db425f 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -1164,7 +1164,6 @@ c_parser_gimple_switch_stmt (c_parser *parser, gimple_seq 
*seq)
   auto_vec labels;
   tree default_label = NULL_TREE;
   gimple_seq switch_body = NULL;
-  location_t loc;
   c_parser_consume_token (parser);
 
   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
@@ -1189,7 +1188,7 @@ c_parser_gimple_switch_stmt (c_parser *parser, gimple_seq 
*seq)
case RID_CASE:
  {
c_expr exp1;
-   loc = c_parser_peek_token (parser)->location;
+   location_t loc = c_parser_peek_token (parser)->location;
c_parser_consume_token (parser);
 
if (c_parser_next_token_is (parser, CPP_NAME)
@@ -1224,6 +1223,7 @@ c_parser_gimple_switch_stmt (c_parser *parser, gimple_seq 
*seq)
  }
case RID_DEFAULT:
  {
+   location_t loc = c_parser_peek_token (parser)->location;
c_parser_consume_token (parser);
if (c_parser_next_token_is (parser, CPP_COLON))
  {
@@ -1250,7 +1250,7 @@ c_parser_gimple_switch_stmt (c_parser *parser, gimple_seq 
*seq)
  }
case RID_GOTO:
  {
-   loc = c_parser_peek_token (parser)->location;
+   location_t loc = c_parser_peek_token (parser)->location;
c_parser_consume_token (parser);
if (c_parser_next_token_is (parser, CPP_NAME))
  {
-- 
2.10.1



[PATCH 7/7] make targetm.gen_ccmp{first,next} take rtx_insn **

2016-10-17 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-10-17  Trevor Saunders  

* ccmp.c (expand_ccmp_expr_1): Adjust.
(expand_ccmp_expr): Likewise.
(expand_ccmp_next): Likewise.
* config/aarch64/aarch64.c (aarch64_gen_ccmp_next): Likewise.
(aarch64_gen_ccmp_first): Likewise.
* doc/tm.texi: Regenerate.
* target.def (gen_ccmp_first): Change argument types to rtx_insn *.
(gen_ccmp_next): Likewise.
---
 gcc/ccmp.c   | 21 ++---
 gcc/config/aarch64/aarch64.c | 10 +-
 gcc/doc/tm.texi  |  4 ++--
 gcc/target.def   |  4 ++--
 4 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/gcc/ccmp.c b/gcc/ccmp.c
index 615b7e6..14222ca 100644
--- a/gcc/ccmp.c
+++ b/gcc/ccmp.c
@@ -122,7 +122,7 @@ ccmp_candidate_p (gimple *g)
GEN_SEQ returns all compare insns.  */
 static rtx
 expand_ccmp_next (gimple *g, tree_code code, rtx prev,
- rtx *prep_seq, rtx *gen_seq)
+ rtx_insn **prep_seq, rtx_insn **gen_seq)
 {
   rtx_code rcode;
   int unsignedp = TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (g)));
@@ -149,10 +149,8 @@ expand_ccmp_next (gimple *g, tree_code code, rtx prev,
PREP_SEQ returns all insns to prepare opearand.
GEN_SEQ returns all compare insns.  */
 static rtx
-expand_ccmp_expr_1 (gimple *g, rtx *prep_seq, rtx *gen_seq)
+expand_ccmp_expr_1 (gimple *g, rtx_insn **prep_seq, rtx_insn **gen_seq)
 {
-  rtx prep_seq_1, gen_seq_1;
-  rtx prep_seq_2, gen_seq_2;
   tree exp = gimple_assign_rhs_to_tree (g);
   tree_code code = TREE_CODE (exp);
   gimple *gs0 = get_gimple_for_ssa_name (TREE_OPERAND (exp, 0));
@@ -180,6 +178,7 @@ expand_ccmp_expr_1 (gimple *g, rtx *prep_seq, rtx *gen_seq)
  rcode0 = get_rtx_code (code0, unsignedp0);
  rcode1 = get_rtx_code (code1, unsignedp1);
 
+ rtx_insn *prep_seq_1, *gen_seq_1;
  tmp = targetm.gen_ccmp_first (_seq_1, _seq_1, rcode0,
gimple_assign_rhs1 (gs0),
gimple_assign_rhs2 (gs0));
@@ -187,14 +186,15 @@ expand_ccmp_expr_1 (gimple *g, rtx *prep_seq, rtx 
*gen_seq)
  if (tmp != NULL)
{
  ret = expand_ccmp_next (gs1, code, tmp, _seq_1, _seq_1);
- cost1 = seq_cost (safe_as_a  (prep_seq_1), speed_p);
- cost1 += seq_cost (safe_as_a  (gen_seq_1), speed_p);
+ cost1 = seq_cost (prep_seq_1, speed_p);
+ cost1 += seq_cost (gen_seq_1, speed_p);
}
 
  /* FIXME: Temporary workaround for PR69619.
 Avoid exponential compile time due to expanding gs0 and gs1 twice.
 If gs0 and gs1 are complex, the cost will be high, so avoid
 reevaluation if above an arbitrary threshold.  */
+ rtx_insn *prep_seq_2, *gen_seq_2;
  if (tmp == NULL || cost1 < COSTS_N_INSNS (25))
tmp2 = targetm.gen_ccmp_first (_seq_2, _seq_2, rcode1,
   gimple_assign_rhs1 (gs1),
@@ -207,8 +207,8 @@ expand_ccmp_expr_1 (gimple *g, rtx *prep_seq, rtx *gen_seq)
{
  ret2 = expand_ccmp_next (gs0, code, tmp2, _seq_2,
   _seq_2);
- cost2 = seq_cost (safe_as_a  (prep_seq_2), speed_p);
- cost2 += seq_cost (safe_as_a  (gen_seq_2), speed_p);
+ cost2 = seq_cost (prep_seq_2, speed_p);
+ cost2 += seq_cost (gen_seq_2, speed_p);
}
 
  if (cost2 < cost1)
@@ -262,14 +262,13 @@ expand_ccmp_expr (gimple *g)
 {
   rtx_insn *last;
   rtx tmp;
-  rtx prep_seq, gen_seq;
-
-  prep_seq = gen_seq = NULL_RTX;
 
   if (!ccmp_candidate_p (g))
 return NULL_RTX;
 
   last = get_last_insn ();
+
+  rtx_insn *prep_seq = NULL, *gen_seq = NULL;
   tmp = expand_ccmp_expr_1 (g, _seq, _seq);
 
   if (tmp)
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 74f1a6a..771421c 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -13160,7 +13160,7 @@ aarch64_use_by_pieces_infrastructure_p (unsigned 
HOST_WIDE_INT size,
 }
 
 static rtx
-aarch64_gen_ccmp_first (rtx *prep_seq, rtx *gen_seq,
+aarch64_gen_ccmp_first (rtx_insn **prep_seq, rtx_insn **gen_seq,
int code, tree treeop0, tree treeop1)
 {
   machine_mode op_mode, cmp_mode, cc_mode = CCmode;
@@ -13234,8 +13234,8 @@ aarch64_gen_ccmp_first (rtx *prep_seq, rtx *gen_seq,
 }
 
 static rtx
-aarch64_gen_ccmp_next (rtx *prep_seq, rtx *gen_seq, rtx prev, int cmp_code,
-  tree treeop0, tree treeop1, int bit_code)
+aarch64_gen_ccmp_next (rtx_insn **prep_seq, rtx_insn **gen_seq, rtx prev,
+  int cmp_code, tree treeop0, tree treeop1, int bit_code)
 {
   rtx op0, op1, target;
   machine_mode op_mode, cmp_mode, cc_mode = CCmode;
@@ -13244,7 +13244,7 @@ aarch64_gen_ccmp_next 

[PATCH 5/7] remove cast in delete_insn_chain

2016-10-17 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-10-17  Trevor Saunders  

* cfgrtl.c (delete_insn_chain): Change argument type to rtx_insn *
and adjust for that.
* cfgrtl.h (delete_insn_chain): Adjust prototype.
---
 gcc/cfgrtl.c | 8 +++-
 gcc/cfgrtl.h | 2 +-
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index 813f7ce..d2719db 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -240,17 +240,15 @@ delete_insn_and_edges (rtx_insn *insn)
insns that cannot be removed to NULL.  */
 
 void
-delete_insn_chain (rtx start, rtx finish, bool clear_bb)
+delete_insn_chain (rtx start, rtx_insn *finish, bool clear_bb)
 {
-  rtx_insn *prev, *current;
-
   /* Unchain the insns one by one.  It would be quicker to delete all of these
  with a single unchaining, rather than one at a time, but we need to keep
  the NOTE's.  */
-  current = safe_as_a  (finish);
+  rtx_insn *current = finish;
   while (1)
 {
-  prev = PREV_INSN (current);
+  rtx_insn *prev = PREV_INSN (current);
   if (NOTE_P (current) && !can_delete_note_p (as_a  (current)))
;
   else
diff --git a/gcc/cfgrtl.h b/gcc/cfgrtl.h
index d81928a..f4c1396 100644
--- a/gcc/cfgrtl.h
+++ b/gcc/cfgrtl.h
@@ -22,7 +22,7 @@ along with GCC; see the file COPYING3.  If not see
 
 extern void delete_insn (rtx);
 extern bool delete_insn_and_edges (rtx_insn *);
-extern void delete_insn_chain (rtx, rtx, bool);
+extern void delete_insn_chain (rtx, rtx_insn *, bool);
 extern basic_block create_basic_block_structure (rtx_insn *, rtx_insn *,
 rtx_note *, basic_block);
 extern void compute_bb_for_insn (void);
-- 
2.9.3



[PATCH 3/7] use rtx_insn * more

2016-10-17 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-10-17  Trevor Saunders  

* config/alpha/alpha.c (alpha_legitimize_address_1): Change
variable types from rtx to rtx_insn *.
(alpha_emit_xfloating_libcall): Likewise.
* config/arc/arc.c (arc_emit_call_tls_get_addr): Likewise.
* config/arm/arm.c (arm_call_tls_get_addr): Likewise.
(legitimize_tls_address): Likewise.
* config/bfin/bfin.c (hwloop_optimize): Likewise.
(bfin_gen_bundles): Likewise.
* config/c6x/c6x.c (reorg_split_calls): Likewise.
(c6x_reorg): Likewise.
* config/frv/frv.c (frv_reorder_packet): Likewise.
* config/i386/i386.c (ix86_split_idivmod): Likewise.
* config/ia64/ia64.c (ia64_expand_compare): Likewise.
* config/m32c/m32c.c (m32c_prepare_shift): Likewise.
* config/mips/mips.c (mips_call_tls_get_addr): Likewise.
(mips_legitimize_tls_address): Likewise.
* config/mn10300/mn10300.c: Likewise.
* config/rl78/rl78.c: Likewise.
* config/s390/s390.c (s390_fix_long_loop_prediction): Likewise.
* config/sh/sh-mem.cc (sh_expand_cmpstr): Likewise.
(sh_expand_cmpnstr): Likewise.
(sh_expand_strlen): Likewise.
(sh_expand_setmem): Likewise.
* config/sh/sh.md: Likewise.
* emit-rtl.c (emit_pattern_before): Likewise.
* except.c: Likewise.
* final.c: Likewise.
* jump.c: Likewise.
* optabs.c (expand_binop): Likewise.
* reload1.c (gen_reload): Likewise.
* reorg.c (relax_delay_slots): Likewise.
---
 gcc/config/alpha/alpha.c | 117 ++-
 gcc/config/arc/arc.c |   3 +-
 gcc/config/arm/arm.c |   9 ++--
 gcc/config/bfin/bfin.c   |   7 +--
 gcc/config/c6x/c6x.c |   9 ++--
 gcc/config/frv/frv.c |   2 +-
 gcc/config/i386/i386.c   |   3 +-
 gcc/config/ia64/ia64.c   |   4 +-
 gcc/config/m32c/m32c.c   |   4 +-
 gcc/config/mips/mips.c   |  61 +++---
 gcc/config/mn10300/mn10300.c |   2 +-
 gcc/config/rl78/rl78.c   |   2 +-
 gcc/config/s390/s390.c   |   7 +--
 gcc/config/sh/sh-mem.cc  |   8 +--
 gcc/config/sh/sh.md  |  18 +++
 gcc/emit-rtl.c   |   2 +-
 gcc/except.c |   2 +-
 gcc/final.c  |   4 +-
 gcc/jump.c   |   4 +-
 gcc/optabs.c |   5 +-
 gcc/reload1.c|   9 ++--
 gcc/reorg.c  |  19 ---
 22 files changed, 156 insertions(+), 145 deletions(-)

diff --git a/gcc/config/alpha/alpha.c b/gcc/config/alpha/alpha.c
index 7f53967..6d390ae 100644
--- a/gcc/config/alpha/alpha.c
+++ b/gcc/config/alpha/alpha.c
@@ -1017,7 +1017,8 @@ alpha_legitimize_address_1 (rtx x, rtx scratch, 
machine_mode mode)
   && GET_MODE_SIZE (mode) <= UNITS_PER_WORD
   && symbolic_operand (x, Pmode))
 {
-  rtx r0, r16, eqv, tga, tp, insn, dest, seq;
+  rtx r0, r16, eqv, tga, tp, dest, seq;
+  rtx_insn *insn;
 
   switch (tls_symbolic_operand_type (x))
{
@@ -1025,66 +1026,70 @@ alpha_legitimize_address_1 (rtx x, rtx scratch, 
machine_mode mode)
  break;
 
case TLS_MODEL_GLOBAL_DYNAMIC:
- start_sequence ();
+ {
+   start_sequence ();
 
- r0 = gen_rtx_REG (Pmode, 0);
- r16 = gen_rtx_REG (Pmode, 16);
- tga = get_tls_get_addr ();
- dest = gen_reg_rtx (Pmode);
- seq = GEN_INT (alpha_next_sequence_number++);
+   r0 = gen_rtx_REG (Pmode, 0);
+   r16 = gen_rtx_REG (Pmode, 16);
+   tga = get_tls_get_addr ();
+   dest = gen_reg_rtx (Pmode);
+   seq = GEN_INT (alpha_next_sequence_number++);
 
- emit_insn (gen_movdi_er_tlsgd (r16, pic_offset_table_rtx, x, seq));
- insn = gen_call_value_osf_tlsgd (r0, tga, seq);
- insn = emit_call_insn (insn);
- RTL_CONST_CALL_P (insn) = 1;
- use_reg (_INSN_FUNCTION_USAGE (insn), r16);
+   emit_insn (gen_movdi_er_tlsgd (r16, pic_offset_table_rtx, x, seq));
+   rtx val = gen_call_value_osf_tlsgd (r0, tga, seq);
+   insn = emit_call_insn (val);
+   RTL_CONST_CALL_P (insn) = 1;
+   use_reg (_INSN_FUNCTION_USAGE (insn), r16);
 
-  insn = get_insns ();
- end_sequence ();
+   insn = get_insns ();
+   end_sequence ();
 
- emit_libcall_block (insn, dest, r0, x);
- return dest;
+   emit_libcall_block (insn, dest, r0, x);
+   return dest;
+ }
 
case TLS_MODEL_LOCAL_DYNAMIC:
- start_sequence ();
+ {
+   start_sequence ();
 
- r0 = gen_rtx_REG (Pmode, 0);
- r16 = gen_rtx_REG (Pmode, 16);
- tga = get_tls_get_addr ();
- scratch = gen_reg_rtx (Pmode);
- seq = GEN_INT (alpha_next_sequence_number++);
+

[PATCH 1/7] make LABEL_REF_LABEL a rtx_insn *

2016-10-17 Thread tbsaunde+gcc
From: Trevor Saunders 

While chainging LABEL_REF_LABEL it might as well become an inline
function, so that its clearer what types are involved.  Unfortunately
because it is still possible to use XEXP and related macros on a
LABEL_REF rtx you can still set the field to be a non insn rtx.  The
other unfortunate thing is that the generators actually create LABEL_REF
rtx that refer to MATCH_x rtx, so there we actually need to use XEXP to
bypass the checking this patch adds.

gcc/ChangeLog:

2016-10-17  Trevor Saunders  

* rtl.h (label_ref_label): New function.
(set_label_ref_label): New function.
(LABEL_REF_LABEL): Delete.
* alias.c (rtx_equal_for_memref_p): Adjust.
* cfgbuild.c (make_edges): Likewise.
(purge_dead_tablejump_edges): Likewise.
* cfgexpand.c (convert_debug_memory_address): Likewise.
* cfgrtl.c (patch_jump_insn): Likewise.
* combine.c (distribute_notes): Likewise.
* cse.c (hash_rtx_cb): Likewise.
(exp_equiv_p): Likewise.
(fold_rtx): Likewise.
(check_for_label_ref): Likewise.
* cselib.c (rtx_equal_for_cselib_1): Likewise.
(cselib_hash_rtx): Likewise.
* emit-rtl.c (mark_label_nuses): Likewise.
* explow.c (convert_memory_address_addr_space_1): Likewise.
* final.c (output_asm_label): Likewise.
(output_addr_const): Likewise.
* gcse.c (add_label_notes): Likewise.
* genconfig.c (walk_insn_part): Likewise.
* genrecog.c (validate_pattern): Likewise.
* ifcvt.c (cond_exec_get_condition): Likewise.
(noce_emit_store_flag): Likewise.
(noce_get_alt_condition): Likewise.
(noce_get_condition): Likewise.
* jump.c (maybe_propagate_label_ref): Likewise.
(mark_jump_label_1): Likewise.
(redirect_exp_1): Likewise.
(rtx_renumbered_equal_p): Likewise.
* lra-constraints.c (operands_match_p): Likewise.
* print-rtl.c (print_value): Likewise.
* reload.c (find_reloads): Likewise.
* reload1.c (set_label_offsets): Likewise.
* reorg.c (get_branch_condition): Likewise.
* rtl-tests.c (test_uncond_jump): Likewise.
* rtl.c (rtx_equal_p_cb): Likewise.
(rtx_equal_p): Likewise.
* rtlanal.c (reg_mentioned_p): Likewise.
(rtx_referenced_p): Likewise.
(get_condition): Likewise.
* varasm.c (const_hash_1): Likewise.
(compare_constant): Likewise.
(const_rtx_hash_1): Likewise.
(output_constant_pool_1): Likewise.
---
 gcc/alias.c   |  2 +-
 gcc/cfgbuild.c|  4 ++--
 gcc/cfgexpand.c   |  2 +-
 gcc/cfgrtl.c  |  2 +-
 gcc/combine.c |  4 ++--
 gcc/cse.c | 20 ++--
 gcc/cselib.c  |  4 ++--
 gcc/emit-rtl.c|  4 ++--
 gcc/explow.c  |  2 +-
 gcc/final.c   |  4 ++--
 gcc/gcse.c|  6 +++---
 gcc/genconfig.c   |  4 ++--
 gcc/genrecog.c|  4 ++--
 gcc/ifcvt.c   |  8 
 gcc/jump.c| 18 --
 gcc/lra-constraints.c |  2 +-
 gcc/print-rtl.c   |  2 +-
 gcc/reload.c  | 12 ++--
 gcc/reload1.c |  6 +++---
 gcc/reorg.c   |  6 +++---
 gcc/rtl-tests.c   |  2 +-
 gcc/rtl.c |  4 ++--
 gcc/rtl.h | 11 ++-
 gcc/rtlanal.c |  6 +++---
 gcc/varasm.c  | 20 +++-
 25 files changed, 84 insertions(+), 75 deletions(-)

diff --git a/gcc/alias.c b/gcc/alias.c
index f4a0a29..ca475ff 100644
--- a/gcc/alias.c
+++ b/gcc/alias.c
@@ -1767,7 +1767,7 @@ rtx_equal_for_memref_p (const_rtx x, const_rtx y)
   return REGNO (x) == REGNO (y);
 
 case LABEL_REF:
-  return LABEL_REF_LABEL (x) == LABEL_REF_LABEL (y);
+  return label_ref_label (x) == label_ref_label (y);
 
 case SYMBOL_REF:
   return compare_base_symbol_refs (x, y) == 1;
diff --git a/gcc/cfgbuild.c b/gcc/cfgbuild.c
index 40c011d..6c70971 100644
--- a/gcc/cfgbuild.c
+++ b/gcc/cfgbuild.c
@@ -275,7 +275,7 @@ make_edges (basic_block min, basic_block max, int update_p)
  && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
  && GET_CODE (XEXP (SET_SRC (tmp), 2)) == LABEL_REF)
make_label_edge (edge_cache, bb,
-LABEL_REF_LABEL (XEXP (SET_SRC (tmp), 2)), 0);
+label_ref_label (XEXP (SET_SRC (tmp), 2)), 0);
}
 
  /* If this is a computed jump, then mark it as reaching
@@ -415,7 +415,7 @@ purge_dead_tablejump_edges (basic_block bb, 
rtx_jump_table_data *table)
&& SET_DEST (tmp) == pc_rtx
&& GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
&& GET_CODE (XEXP (SET_SRC (tmp), 2)) == LABEL_REF)
-mark_tablejump_edge (LABEL_REF_LABEL (XEXP (SET_SRC (tmp), 2)));
+mark_tablejump_edge (label_ref_label (XEXP (SET_SRC (tmp), 

[PATCH 6/7] remove cast from prev_nonnote_insn_bb

2016-10-17 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-10-17  Trevor Saunders  

* emit-rtl.c (prev_nonnote_insn_bb): Change argument type to
rtx_insn *.
* rtl.h (prev_nonnote_insn_bb): Adjust prototype.
---
 gcc/emit-rtl.c | 3 +--
 gcc/rtl.h  | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index a8516eb..e27587b 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3354,9 +3354,8 @@ prev_nonnote_insn (rtx_insn *insn)
not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nonnote_insn_bb (rtx uncast_insn)
+prev_nonnote_insn_bb (rtx_insn *insn)
 {
-  rtx_insn *insn = safe_as_a  (uncast_insn);
 
   while (insn)
 {
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 9abb054..3901749 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2856,7 +2856,7 @@ extern rtx_call_insn *last_call_insn (void);
 extern rtx_insn *previous_insn (rtx_insn *);
 extern rtx_insn *next_insn (rtx_insn *);
 extern rtx_insn *prev_nonnote_insn (rtx_insn *);
-extern rtx_insn *prev_nonnote_insn_bb (rtx);
+extern rtx_insn *prev_nonnote_insn_bb (rtx_insn *);
 extern rtx_insn *next_nonnote_insn (rtx_insn *);
 extern rtx_insn *next_nonnote_insn_bb (rtx_insn *);
 extern rtx_insn *prev_nondebug_insn (rtx_insn *);
-- 
2.9.3



[PATCH 2/7] make tablejump_p return the label as a rtx_insn *

2016-10-17 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-10-17  Trevor Saunders  

* cfgcleanup.c (merge_blocks_move_successor_nojumps): Adjust.
(outgoing_edges_match): Likewise.
(try_crossjump_to_edge): Likewise.
* cfgrtl.c (try_redirect_by_replacing_jump): Likewise.
(rtl_tidy_fallthru_edge): Likewise.
* rtl.h (tablejump_p): Adjust prototype.
* rtlanal.c (tablejump_p): Return the label as a rtx_insn *.
---
 gcc/cfgcleanup.c |  8 
 gcc/cfgrtl.c |  7 +++
 gcc/rtl.h|  2 +-
 gcc/rtlanal.c| 32 
 4 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/gcc/cfgcleanup.c b/gcc/cfgcleanup.c
index 1c9691d..c67b4d7 100644
--- a/gcc/cfgcleanup.c
+++ b/gcc/cfgcleanup.c
@@ -688,7 +688,7 @@ static void
 merge_blocks_move_successor_nojumps (basic_block a, basic_block b)
 {
   rtx_insn *barrier, *real_b_end;
-  rtx label;
+  rtx_insn *label;
   rtx_jump_table_data *table;
 
   /* If we are partitioning hot/cold basic blocks, we don't want to
@@ -709,7 +709,7 @@ merge_blocks_move_successor_nojumps (basic_block a, 
basic_block b)
   /* If there is a jump table following block B temporarily add the jump table
  to block B so that it will also be moved to the correct location.  */
   if (tablejump_p (BB_END (b), , )
-  && prev_active_insn (as_a (label)) == BB_END (b))
+  && prev_active_insn (label) == BB_END (b))
 {
   BB_END (b) = table;
 }
@@ -1697,7 +1697,7 @@ outgoing_edges_match (int mode, basic_block bb1, 
basic_block bb2)
   /* Check whether there are tablejumps in the end of BB1 and BB2.
  Return true if they are identical.  */
 {
-  rtx label1, label2;
+  rtx_insn *label1, *label2;
   rtx_jump_table_data *table1, *table2;
 
   if (tablejump_p (BB_END (bb1), , )
@@ -1994,7 +1994,7 @@ try_crossjump_to_edge (int mode, edge e1, edge e2,
  they have been already compared for equivalence in outgoing_edges_match ()
  so replace the references to TABLE1 by references to TABLE2.  */
   {
-  rtx label1, label2;
+  rtx_insn *label1, *label2;
   rtx_jump_table_data *table1, *table2;
 
   if (tablejump_p (BB_END (osrc1), , )
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index 67cab71..813f7ce 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -1101,7 +1101,7 @@ try_redirect_by_replacing_jump (edge e, basic_block 
target, bool in_cfglayout)
 {
   rtx_code_label *target_label = block_label (target);
   rtx_insn *barrier;
-  rtx label;
+  rtx_insn *label;
   rtx_jump_table_data *table;
 
   emit_jump_insn_after_noloc (targetm.gen_jump (target_label), insn);
@@ -1773,7 +1773,7 @@ rtl_tidy_fallthru_edge (edge e)
   && (any_uncondjump_p (q)
  || single_succ_p (b)))
 {
-  rtx label;
+  rtx_insn *label;
   rtx_jump_table_data *table;
 
   if (tablejump_p (q, , ))
@@ -1786,8 +1786,7 @@ rtl_tidy_fallthru_edge (edge e)
  PUT_CODE (label, NOTE);
  NOTE_KIND (label) = NOTE_INSN_DELETED_LABEL;
  NOTE_DELETED_LABEL_NAME (label) = name;
- rtx_insn *lab = safe_as_a  (label);
- reorder_insns (lab, lab, PREV_INSN (q));
+ reorder_insns (label, label, PREV_INSN (q));
  delete_insn (table);
}
 
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 7ee0b61..c84fe71 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -3038,7 +3038,7 @@ extern rtx replace_rtx (rtx, rtx, rtx, bool = false);
 extern void replace_label (rtx *, rtx, rtx, bool);
 extern void replace_label_in_insn (rtx_insn *, rtx, rtx, bool);
 extern bool rtx_referenced_p (const_rtx, const_rtx);
-extern bool tablejump_p (const rtx_insn *, rtx *, rtx_jump_table_data **);
+extern bool tablejump_p (const rtx_insn *, rtx_insn **, rtx_jump_table_data 
**);
 extern int computed_jump_p (const rtx_insn *);
 extern bool tls_referenced_p (const_rtx);
 
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index 90b55b6..4e600c0 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -3103,26 +3103,26 @@ rtx_referenced_p (const_rtx x, const_rtx body)
*LABELP and the jump table to *TABLEP.  LABELP and TABLEP may be NULL.  */
 
 bool
-tablejump_p (const rtx_insn *insn, rtx *labelp, rtx_jump_table_data **tablep)
+tablejump_p (const rtx_insn *insn, rtx_insn **labelp,
+rtx_jump_table_data **tablep)
 {
-  rtx label;
-  rtx_insn *table;
-
   if (!JUMP_P (insn))
 return false;
 
-  label = JUMP_LABEL (insn);
-  if (label != NULL_RTX && !ANY_RETURN_P (label)
-  && (table = NEXT_INSN (as_a  (label))) != NULL_RTX
-  && JUMP_TABLE_DATA_P (table))
-{
-  if (labelp)
-   *labelp = label;
-  if (tablep)
-   *tablep = as_a  (table);
-  return true;
-}
-  return false;
+  rtx target = JUMP_LABEL (insn);
+  if (target == NULL_RTX || ANY_RETURN_P (target))
+return false;
+
+  rtx_insn *label = as_a (target);
+  rtx_insn *table = next_insn (label);
+  if 

[PATCH 4/7] remove cast to rtx_insn * in remove_note

2016-10-17 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-10-17  Trevor Saunders  

* config/rl78/rl78.c (gen-and_emit_move): Change argument type
to rtx_insn *.
(transcode_memory_rtx): Likewise.
(move_to_acc): Likewise.
(move_from_acc): Likewise.
(move_acc_to_reg): Likewise.
(move_to_x): Likewise.
(move_to_hl): Likewise.
(move_to_de): Likewise.
* config/rs6000/rs6000.c (emit_frame_save): Likewise.
(rs6000_emit_savres_rtx): Likewise.
(rs6000_emit_prologue): Likewise.
* reorg.c (update_reg_unused_notes): Likewise.
* rtl.h (remove_note): Adjust prototype.
* rtlanal.c (remove_note): Make argument type rtx_insn *.
---
 gcc/config/rl78/rl78.c | 16 
 gcc/config/rs6000/rs6000.c | 26 ++
 gcc/reorg.c|  4 ++--
 gcc/rtl.h  |  2 +-
 gcc/rtlanal.c  |  4 ++--
 5 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/gcc/config/rl78/rl78.c b/gcc/config/rl78/rl78.c
index fd72a58..db3e25f 100644
--- a/gcc/config/rl78/rl78.c
+++ b/gcc/config/rl78/rl78.c
@@ -2778,7 +2778,7 @@ process_postponed_content_update (void)
after WHERE.  If TO already contains FROM then do nothing.  Returns TO if
BEFORE is true, FROM otherwise.  */
 static rtx
-gen_and_emit_move (rtx to, rtx from, rtx where, bool before)
+gen_and_emit_move (rtx to, rtx from, rtx_insn *where, bool before)
 {
   machine_mode mode = GET_MODE (to);
 
@@ -2833,7 +2833,7 @@ gen_and_emit_move (rtx to, rtx from, rtx where, bool 
before)
copy it into NEWBASE and return the updated MEM.  Otherwise just
return M.  Any needed insns are emitted before BEFORE.  */
 static rtx
-transcode_memory_rtx (rtx m, rtx newbase, rtx before)
+transcode_memory_rtx (rtx m, rtx newbase, rtx_insn *before)
 {
   rtx base, index, addendr;
   int addend = 0;
@@ -2934,7 +2934,7 @@ transcode_memory_rtx (rtx m, rtx newbase, rtx before)
 /* Copy SRC to accumulator (A or AX), placing any generated insns
before BEFORE.  Returns accumulator RTX.  */
 static rtx
-move_to_acc (int opno, rtx before)
+move_to_acc (int opno, rtx_insn *before)
 {
   rtx src = OP (opno);
   machine_mode mode = GET_MODE (src);
@@ -2968,7 +2968,7 @@ force_into_acc (rtx src, rtx_insn *before)
 /* Copy accumulator (A or AX) to DEST, placing any generated insns
after AFTER.  Returns accumulator RTX.  */
 static rtx
-move_from_acc (unsigned int opno, rtx after)
+move_from_acc (unsigned int opno, rtx_insn *after)
 {
   rtx dest = OP (opno);
   machine_mode mode = GET_MODE (dest);
@@ -2982,7 +2982,7 @@ move_from_acc (unsigned int opno, rtx after)
 /* Copy accumulator (A or AX) to REGNO, placing any generated insns
before BEFORE.  Returns reg RTX.  */
 static rtx
-move_acc_to_reg (rtx acc, int regno, rtx before)
+move_acc_to_reg (rtx acc, int regno, rtx_insn *before)
 {
   machine_mode mode = GET_MODE (acc);
   rtx reg;
@@ -2995,7 +2995,7 @@ move_acc_to_reg (rtx acc, int regno, rtx before)
 /* Copy SRC to X, placing any generated insns before BEFORE.
Returns X RTX.  */
 static rtx
-move_to_x (int opno, rtx before)
+move_to_x (int opno, rtx_insn *before)
 {
   rtx src = OP (opno);
   machine_mode mode = GET_MODE (src);
@@ -3018,7 +3018,7 @@ move_to_x (int opno, rtx before)
 /* Copy OP (opno) to H or HL, placing any generated insns before BEFORE.
Returns H/HL RTX.  */
 static rtx
-move_to_hl (int opno, rtx before)
+move_to_hl (int opno, rtx_insn *before)
 {
   rtx src = OP (opno);
   machine_mode mode = GET_MODE (src);
@@ -3041,7 +3041,7 @@ move_to_hl (int opno, rtx before)
 /* Copy OP (opno) to E or DE, placing any generated insns before BEFORE.
Returns E/DE RTX.  */
 static rtx
-move_to_de (int opno, rtx before)
+move_to_de (int opno, rtx_insn *before)
 {
   rtx src = OP (opno);
   machine_mode mode = GET_MODE (src);
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 613af48..b5f1dc9 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -26805,8 +26805,8 @@ output_probe_stack_range (rtx reg1, rtx reg2)
pointer.  That fails when saving regs off r1, and sched moves the
r31 setup past the reg saves.  */
 
-static rtx
-rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
+static rtx_insn *
+rs6000_frame_related (rtx_insn *insn, rtx reg, HOST_WIDE_INT val,
  rtx reg2, rtx repl2)
 {
   rtx repl;
@@ -26970,11 +26970,11 @@ gen_frame_store (rtx reg, rtx frame_reg, int offset)
 /* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
Save REGNO into [FRAME_REG + OFFSET] in mode MODE.  */
 
-static rtx
+static rtx_insn *
 emit_frame_save (rtx frame_reg, machine_mode mode,
 unsigned int regno, int offset, HOST_WIDE_INT frame_reg_to_sp)
 {
-  rtx reg, insn;
+  rtx reg;
 
   /* Some cases that need register indexed addressing.  */
   

[PATCH 0/7] more rtx-insn stuff

2016-10-17 Thread tbsaunde+gcc
From: Trevor Saunders 

Hi,

Rather late (travel and then busy day job interfiered), but this includes the
promised conversion of LABEL_REF_LABEL and tablejump_p to use rtx_insn *.  
Followed by a bit more random conversion of things to use rtx_insn *.

patches individually bootstrapped + regtested on x86_64-linux-gnu, and run
through config-list.mk as a whole.  Ok?

Thanks!

Trev

Trevor Saunders (7):
  make LABEL_REF_LABEL a rtx_insn *
  make tablejump_p return the label as a rtx_insn *
  use rtx_insn * more
  remove cast to rtx_insn * in remove_note
  remove cast in delete_insn_chain
  remove cast from prev_nonnote_insn_bb
  make targetm.gen_ccmp{first,next} take rtx_insn **

 gcc/alias.c  |   2 +-
 gcc/ccmp.c   |  21 
 gcc/cfgbuild.c   |   4 +-
 gcc/cfgcleanup.c |   8 +--
 gcc/cfgexpand.c  |   2 +-
 gcc/cfgrtl.c |  17 +++
 gcc/cfgrtl.h |   2 +-
 gcc/combine.c|   4 +-
 gcc/config/aarch64/aarch64.c |  10 ++--
 gcc/config/alpha/alpha.c | 117 ++-
 gcc/config/arc/arc.c |   3 +-
 gcc/config/arm/arm.c |   9 ++--
 gcc/config/bfin/bfin.c   |   7 +--
 gcc/config/c6x/c6x.c |   9 ++--
 gcc/config/frv/frv.c |   2 +-
 gcc/config/i386/i386.c   |   3 +-
 gcc/config/ia64/ia64.c   |   4 +-
 gcc/config/m32c/m32c.c   |   4 +-
 gcc/config/mips/mips.c   |  61 +++---
 gcc/config/mn10300/mn10300.c |   2 +-
 gcc/config/rl78/rl78.c   |  18 +++
 gcc/config/rs6000/rs6000.c   |  26 +-
 gcc/config/s390/s390.c   |   7 +--
 gcc/config/sh/sh-mem.cc  |   8 +--
 gcc/config/sh/sh.md  |  18 +++
 gcc/cse.c|  20 
 gcc/cselib.c |   4 +-
 gcc/doc/tm.texi  |   4 +-
 gcc/emit-rtl.c   |   9 ++--
 gcc/except.c |   2 +-
 gcc/explow.c |   2 +-
 gcc/final.c  |   8 +--
 gcc/gcse.c   |   6 +--
 gcc/genconfig.c  |   4 +-
 gcc/genrecog.c   |   4 +-
 gcc/ifcvt.c  |   8 +--
 gcc/jump.c   |  22 
 gcc/lra-constraints.c|   2 +-
 gcc/optabs.c |   5 +-
 gcc/print-rtl.c  |   2 +-
 gcc/reload.c |  12 ++---
 gcc/reload1.c|  15 +++---
 gcc/reorg.c  |  29 ++-
 gcc/rtl-tests.c  |   2 +-
 gcc/rtl.c|   4 +-
 gcc/rtl.h|  17 +--
 gcc/rtlanal.c|  42 
 gcc/target.def   |   4 +-
 gcc/varasm.c |  20 
 49 files changed, 316 insertions(+), 299 deletions(-)

-- 
2.9.3



[PATCH 5/8] make prev_real_insn take rtx_insn *

2016-09-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-09-13  Trevor Saunders  

* emit-rtl.c (prev_real_insn): Change argument type to rtx_insn *.
* rtl.h: Adjust prototype.
* config/sh/sh.md: Adjust.
* dwarf2out.c (add_var_loc_to_decl): Likewise.
---
 gcc/config/sh/sh.md | 3 ++-
 gcc/dwarf2out.c | 2 +-
 gcc/emit-rtl.c  | 4 +---
 gcc/rtl.h   | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/gcc/config/sh/sh.md b/gcc/config/sh/sh.md
index edc4d15..25e03ef 100644
--- a/gcc/config/sh/sh.md
+++ b/gcc/config/sh/sh.md
@@ -7178,7 +7178,8 @@
  (label_ref (match_operand 1 "" ""
(use (label_ref (match_operand 2 "" "")))]
   "TARGET_SH2
-   && (! INSN_UID (operands[1]) || prev_real_insn (operands[1]) == insn)"
+   && (! INSN_UID (operands[1])
+   || prev_real_insn (as_a (operands[1])) == insn)"
   "braf%0%#"
   [(set_attr "needs_delay_slot" "yes")
(set_attr "type" "jump_ind")])
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 45eb684..fb8ec7d 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -5408,7 +5408,7 @@ add_var_loc_to_decl (tree decl, rtx loc_note, const char 
*label)
   && NOTE_VAR_LOCATION_LOC (temp->first->loc)
   && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
 == GET_CODE (DECL_INCOMING_RTL (decl))
-  && prev_real_insn (temp->first->loc) == NULL_RTX
+  && prev_real_insn (as_a (temp->first->loc)) == NULL_RTX
   && (bitsize != -1
  || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
   NOTE_VAR_LOCATION_LOC (loc_note))
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 6051326..df5d359 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3461,10 +3461,8 @@ next_real_insn (rtx uncast_insn)
SEQUENCEs.  */
 
 rtx_insn *
-prev_real_insn (rtx uncast_insn)
+prev_real_insn (rtx_insn *insn)
 {
-  rtx_insn *insn = safe_as_a  (uncast_insn);
-
   while (insn)
 {
   insn = PREV_INSN (insn);
diff --git a/gcc/rtl.h b/gcc/rtl.h
index b557ffe..c253fda 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2842,7 +2842,7 @@ extern rtx_insn *prev_nondebug_insn (rtx_insn *);
 extern rtx_insn *next_nondebug_insn (rtx_insn *);
 extern rtx_insn *prev_nonnote_nondebug_insn (rtx);
 extern rtx_insn *next_nonnote_nondebug_insn (rtx);
-extern rtx_insn *prev_real_insn (rtx);
+extern rtx_insn *prev_real_insn (rtx_insn *);
 extern rtx_insn *next_real_insn (rtx);
 extern rtx_insn *prev_active_insn (rtx);
 extern rtx_insn *next_active_insn (rtx);
-- 
2.9.3



[PATCH 7/8] make next/prev active_insn and active_insn_p take rtx_insn *

2016-09-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-09-14  Trevor Saunders  

* emit-rtl.c (next_active_insn): Change argument type to
rtx_insn *.
(prev_active_insn): Likewise.
(active_insn_p): Likewise.
* rtl.h: Adjust prototypes.
* cfgcleanup.c (merge_blocks_move_successor_nojumps): Adjust.
* config/arc/arc.md: Likewise.
* config/pa/pa.c (branch_to_delay_slot_p): Likewise.
(branch_needs_nop_p): Likewise.
(use_skip_p): Likewise.
* config/sh/sh.c (gen_block_redirect): Likewise.
(split_branches): Likewise.
* reorg.c (optimize_skip): Likewise.
(fill_simple_delay_slots): Likewise.
(fill_slots_from_thread): Likewise.
(relax_delay_slots): Likewise.
* resource.c (mark_target_live_regs): Likewise.
---
 gcc/cfgcleanup.c  |  2 +-
 gcc/config/arc/arc.md | 33 +++--
 gcc/config/pa/pa.c|  6 +++---
 gcc/config/sh/sh.c|  8 
 gcc/emit-rtl.c| 10 +++---
 gcc/reorg.c   | 29 +
 gcc/resource.c|  2 +-
 gcc/rtl.h |  6 +++---
 8 files changed, 55 insertions(+), 41 deletions(-)

diff --git a/gcc/cfgcleanup.c b/gcc/cfgcleanup.c
index 023b9d2..2e2a635 100644
--- a/gcc/cfgcleanup.c
+++ b/gcc/cfgcleanup.c
@@ -708,7 +708,7 @@ merge_blocks_move_successor_nojumps (basic_block a, 
basic_block b)
   /* If there is a jump table following block B temporarily add the jump table
  to block B so that it will also be moved to the correct location.  */
   if (tablejump_p (BB_END (b), , )
-  && prev_active_insn (label) == BB_END (b))
+  && prev_active_insn (as_a (label)) == BB_END (b))
 {
   BB_END (b) = table;
 }
diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index 22fdbba..ac7346b 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -5122,16 +5122,29 @@
  scan = as_a  (XEXP (SET_SRC (PATTERN (scan)), 0));
  continue;
}
- if (JUMP_LABEL (scan)
- /* JUMP_LABEL might be simple_return instead if an insn.  */
- && (!INSN_P (JUMP_LABEL (scan))
- || (!next_active_insn (JUMP_LABEL (scan))
- || (recog_memoized (next_active_insn (JUMP_LABEL 
(scan)))
- != CODE_FOR_doloop_begin_i)))
- && (!next_active_insn (NEXT_INSN (PREV_INSN (scan)))
- || (recog_memoized
-  (next_active_insn (NEXT_INSN (PREV_INSN (scan
- != CODE_FOR_doloop_begin_i)))
+
+ rtx lab = JUMP_LABEL (scan);
+ if (!lab)
+   break;
+
+ rtx_insn *next_scan
+   = next_active_insn (NEXT_INSN (PREV_INSN (scan)));
+ if (next_scan
+ && recog_memoized (next_scan) != CODE_FOR_doloop_begin_i)
+   break;
+
+ /* JUMP_LABEL might be simple_return instead if an insn.  */
+ if (!INSN_P (lab))
+   {
+ n_insns++;
+ break;
+   }
+
+ rtx_insn *next_lab = next_active_insn (as_a (lab));
+ if (next_lab
+ && recog_memoized (next_lab) != CODE_FOR_doloop_begin_i)
+   break;
+
n_insns++;
}
  break;
diff --git a/gcc/config/pa/pa.c b/gcc/config/pa/pa.c
index 251c1ad..9c15504 100644
--- a/gcc/config/pa/pa.c
+++ b/gcc/config/pa/pa.c
@@ -6442,7 +6442,7 @@ branch_to_delay_slot_p (rtx_insn *insn)
   if (dbr_sequence_length ())
 return FALSE;
 
-  jump_insn = next_active_insn (JUMP_LABEL (insn));
+  jump_insn = next_active_insn (JUMP_LABEL_AS_INSN (insn));
   while (insn)
 {
   insn = next_active_insn (insn);
@@ -6476,7 +6476,7 @@ branch_needs_nop_p (rtx_insn *insn)
   if (dbr_sequence_length ())
 return FALSE;
 
-  jump_insn = next_active_insn (JUMP_LABEL (insn));
+  jump_insn = next_active_insn (JUMP_LABEL_AS_INSN (insn));
   while (insn)
 {
   insn = next_active_insn (insn);
@@ -6499,7 +6499,7 @@ branch_needs_nop_p (rtx_insn *insn)
 static bool
 use_skip_p (rtx_insn *insn)
 {
-  rtx_insn *jump_insn = next_active_insn (JUMP_LABEL (insn));
+  rtx_insn *jump_insn = next_active_insn (JUMP_LABEL_AS_INSN (insn));
 
   while (insn)
 {
diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index b3e949e..a9b5a14 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -5503,7 +5503,8 @@ gen_block_redirect (rtx_insn *jump, int addr, int 
need_block)
 
   else if (optimize && need_block >= 0)
 {
-  rtx_insn *next = next_active_insn (next_active_insn (dest));
+  rtx_insn *next = next_active_insn (as_a (dest));
+  next = next_active_insn (next);
   if (next && JUMP_P (next)
  && GET_CODE (PATTERN (next)) == SET
  && 

[PATCH 8/8] make next_cc0_user take rtx_insn *

2016-09-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-09-14  Trevor Saunders  

* emit-rtl.c (next_cc0_user): Make argument type rtx_insn *.
* rtl.h: Adjust prototype.
---
 gcc/emit-rtl.c | 4 +---
 gcc/rtl.h  | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index e794613..1519aa5 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3540,10 +3540,8 @@ prev_active_insn (rtx_insn *insn)
Return 0 if we can't find the insn.  */
 
 rtx_insn *
-next_cc0_user (rtx uncast_insn)
+next_cc0_user (rtx_insn *insn)
 {
-  rtx_insn *insn = safe_as_a  (uncast_insn);
-
   rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
 
   if (note)
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 22ee2e6..ce1131b 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2847,7 +2847,7 @@ extern rtx_insn *next_real_insn (rtx);
 extern rtx_insn *prev_active_insn (rtx_insn *);
 extern rtx_insn *next_active_insn (rtx_insn *);
 extern int active_insn_p (const rtx_insn *);
-extern rtx_insn *next_cc0_user (rtx);
+extern rtx_insn *next_cc0_user (rtx_insn *);
 extern rtx_insn *prev_cc0_setter (rtx_insn *);
 
 /* In emit-rtl.c  */
-- 
2.9.3



[PATCH 6/8] make next/prev nonnote_nondebug_insn take rtx_insn *

2016-09-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-09-14  Trevor Saunders  

* config/cris/cris.c (cris_asm_output_case_end): Change argument
type to rtx_insn *.
* emit-rtl.c (next_nonnote_nondebug_insn): Likewise.
(prev_nonnote_nondebug_insn): Likewise.
* config/cris/cris-protos.h: Adjust prototype.
* rtl.h: Likewise.
* jump.c (rtx_renumbered_equal_p): Adjust.
---
 gcc/config/cris/cris-protos.h |  2 +-
 gcc/config/cris/cris.c| 12 ++--
 gcc/emit-rtl.c|  8 ++--
 gcc/jump.c|  6 --
 gcc/rtl.h |  4 ++--
 5 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/gcc/config/cris/cris-protos.h b/gcc/config/cris/cris-protos.h
index 5e0ae61..028c2b7 100644
--- a/gcc/config/cris/cris-protos.h
+++ b/gcc/config/cris/cris-protos.h
@@ -44,7 +44,7 @@ extern bool cris_store_multiple_op_p (rtx);
 extern bool cris_movem_load_rest_p (rtx, int);
 extern void cris_asm_output_symbol_ref (FILE *, rtx);
 extern int cris_cfun_uses_pic_table (void);
-extern void cris_asm_output_case_end (FILE *, int, rtx);
+extern void cris_asm_output_case_end (FILE *, int, rtx_insn *);
 extern rtx cris_gen_movem_load (rtx, rtx, int);
 extern rtx cris_emit_movem_store (rtx, rtx, int, bool);
 extern void cris_expand_pic_call_address (rtx *, rtx *);
diff --git a/gcc/config/cris/cris.c b/gcc/config/cris/cris.c
index 39118f0..bd49152 100644
--- a/gcc/config/cris/cris.c
+++ b/gcc/config/cris/cris.c
@@ -2586,11 +2586,11 @@ cris_asm_output_ident (const char *string)
 /* The ASM_OUTPUT_CASE_END worker.  */
 
 void
-cris_asm_output_case_end (FILE *stream, int num, rtx table)
+cris_asm_output_case_end (FILE *stream, int num, rtx_insn *table)
 {
   /* Step back, over the label for the table, to the actual casejump and
  assert that we find only what's expected.  */
-  rtx whole_jump_insn = prev_nonnote_nondebug_insn (table);
+  rtx_insn *whole_jump_insn = prev_nonnote_nondebug_insn (table);
   gcc_assert (whole_jump_insn != NULL_RTX && LABEL_P (whole_jump_insn));
   whole_jump_insn = prev_nonnote_nondebug_insn (whole_jump_insn);
   gcc_assert (whole_jump_insn != NULL_RTX
@@ -2598,15 +2598,15 @@ cris_asm_output_case_end (FILE *stream, int num, rtx 
table)
  || (TARGET_V32 && INSN_P (whole_jump_insn)
  && GET_CODE (PATTERN (whole_jump_insn)) == SEQUENCE)));
   /* Get the pattern of the casejump, so we can extract the default label.  */
-  whole_jump_insn = PATTERN (whole_jump_insn);
+  rtx whole_jump_pat = PATTERN (whole_jump_insn);
 
   if (TARGET_V32)
 {
   /* This can be a SEQUENCE, meaning the delay-slot of the jump is
 filled.  We also output the offset word a little differently.  */
   rtx parallel_jump
-   = (GET_CODE (whole_jump_insn) == SEQUENCE
-  ? PATTERN (XVECEXP (whole_jump_insn, 0, 0)) : whole_jump_insn);
+   = (GET_CODE (whole_jump_pat) == SEQUENCE
+  ? PATTERN (XVECEXP (whole_jump_pat, 0, 0)) : whole_jump_pat);
 
   asm_fprintf (stream,
   "\t.word %LL%d-.%s\n",
@@ -2621,7 +2621,7 @@ cris_asm_output_case_end (FILE *stream, int num, rtx 
table)
   "\t.word %LL%d-%LL%d%s\n",
   CODE_LABEL_NUMBER (XEXP
  (XEXP
-  (XEXP (XVECEXP (whole_jump_insn, 0, 0), 1), 
+  (XEXP (XVECEXP (whole_jump_pat, 0, 0), 1),
2), 0)),
   num,
   (TARGET_PDEBUG ? "; default" : ""));
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index df5d359..20d8250 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3405,10 +3405,8 @@ prev_nondebug_insn (rtx_insn *insn)
This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-next_nonnote_nondebug_insn (rtx uncast_insn)
+next_nonnote_nondebug_insn (rtx_insn *insn)
 {
-  rtx_insn *insn = safe_as_a  (uncast_insn);
-
   while (insn)
 {
   insn = NEXT_INSN (insn);
@@ -3423,10 +3421,8 @@ next_nonnote_nondebug_insn (rtx uncast_insn)
This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nonnote_nondebug_insn (rtx uncast_insn)
+prev_nonnote_nondebug_insn (rtx_insn *insn)
 {
-  rtx_insn *insn = safe_as_a  (uncast_insn);
-
   while (insn)
 {
   insn = PREV_INSN (insn);
diff --git a/gcc/jump.c b/gcc/jump.c
index 87a1a5d..2164c3b 100644
--- a/gcc/jump.c
+++ b/gcc/jump.c
@@ -1806,8 +1806,10 @@ rtx_renumbered_equal_p (const_rtx x, const_rtx y)
 in the same position in the instruction stream.  */
   else
{
- rtx_insn *xi = next_nonnote_nondebug_insn (LABEL_REF_LABEL (x));
- rtx_insn *yi = next_nonnote_nondebug_insn (LABEL_REF_LABEL (y));
+ rtx_insn *xi = next_nonnote_nondebug_insn
+   (as_a (LABEL_REF_LABEL (x)));
+ rtx_insn *yi = next_nonnote_nondebug_insn
+   (as_a 

[PATCH 3/8] make next/prev _nonnote_insn take rtx_insn *

2016-09-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-09-13  Trevor Saunders  

* emit-rtl.c (next_nonnote_insn): Change argument type to
rtx_insn *.
(prev_nonnote_insn): Likewise.
* jump.c (reversed_comparison_code_parts): Likewise.
(reversed_comparison): Likewise.
* rtl.h: Adjust prototypes.
* config/arc/arc.md: Adjust.
* cse.c (find_comparison_args): Likewise.
* reorg.c (redundant_insn): Change return type to rtx_insn *.
(fix_reg_dead_note): Change argument type to rtx_insn *.
(delete_prior_computation): Likewise.
(delete_computation): Likewise.
(fill_slots_from_thread): Adjust.
(relax_delay_slots): Likewise.
* simplify-rtx.c (simplify_unary_operation_1): Likewise.
(simplify_relational_operation_1): Likewise.
(simplify_ternary_operation): Likewise.
---
 gcc/config/arc/arc.md | 10 ++
 gcc/cse.c |  2 +-
 gcc/emit-rtl.c|  7 ++-
 gcc/jump.c| 12 ++--
 gcc/reorg.c   | 22 +++---
 gcc/rtl.h |  8 
 gcc/simplify-rtx.c|  8 
 7 files changed, 34 insertions(+), 35 deletions(-)

diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index 1102c53..22fdbba 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -3879,7 +3879,7 @@
   ""
   "*
 {
-  rtx diff_vec = PATTERN (next_nonnote_insn (operands[3]));
+  rtx diff_vec = PATTERN (next_nonnote_insn (as_a (operands[3])));
 
   if (GET_CODE (diff_vec) != ADDR_DIFF_VEC)
 {
@@ -3907,10 +3907,12 @@
   [(set_attr "type" "load")
(set_attr_alternative "iscompact"
  [(cond
-   [(ne (symbol_ref "GET_MODE (PATTERN (next_nonnote_insn (operands[3])))")
+   [(ne (symbol_ref "GET_MODE (PATTERN (next_nonnote_insn
+  (as_a 
(operands[3]")
 (symbol_ref "QImode"))
 (const_string "false")
-(match_test "!ADDR_DIFF_VEC_FLAGS (PATTERN (next_nonnote_insn 
(operands[3]))).offset_unsigned")
+(match_test "!ADDR_DIFF_VEC_FLAGS (PATTERN (next_nonnote_insn
+  (as_a 
(operands[3].offset_unsigned")
 (const_string "false")]
(const_string "true"))
   (const_string "false")
@@ -3946,7 +3948,7 @@
   "TARGET_COMPACT_CASESI"
   "*
 {
-  rtx diff_vec = PATTERN (next_nonnote_insn (operands[1]));
+  rtx diff_vec = PATTERN (next_nonnote_insn (as_a (operands[1])));
   int unalign = arc_get_unalign ();
   rtx xop[3];
   const char *s;
diff --git a/gcc/cse.c b/gcc/cse.c
index 0bfd7ff..8637d57 100644
--- a/gcc/cse.c
+++ b/gcc/cse.c
@@ -3054,7 +3054,7 @@ find_comparison_args (enum rtx_code code, rtx *parg1, rtx 
*parg2,
 with floating-point operands.  */
   if (reverse_code)
{
- enum rtx_code reversed = reversed_comparison_code (x, NULL_RTX);
+ enum rtx_code reversed = reversed_comparison_code (x, NULL);
  if (reversed == UNKNOWN)
break;
  else
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index a724608..cbea214 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3301,9 +3301,8 @@ previous_insn (rtx_insn *insn)
look inside SEQUENCEs.  */
 
 rtx_insn *
-next_nonnote_insn (rtx uncast_insn)
+next_nonnote_insn (rtx_insn *insn)
 {
-  rtx_insn *insn = safe_as_a  (uncast_insn);
   while (insn)
 {
   insn = NEXT_INSN (insn);
@@ -3337,10 +3336,8 @@ next_nonnote_insn_bb (rtx_insn *insn)
not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nonnote_insn (rtx uncast_insn)
+prev_nonnote_insn (rtx_insn *insn)
 {
-  rtx_insn *insn = safe_as_a  (uncast_insn);
-
   while (insn)
 {
   insn = PREV_INSN (insn);
diff --git a/gcc/jump.c b/gcc/jump.c
index 22f8a71..87a1a5d 100644
--- a/gcc/jump.c
+++ b/gcc/jump.c
@@ -62,7 +62,7 @@ static void mark_all_labels (rtx_insn *);
 static void mark_jump_label_1 (rtx, rtx_insn *, bool, bool);
 static void mark_jump_label_asm (rtx, rtx_insn *);
 static void redirect_exp_1 (rtx *, rtx, rtx, rtx);
-static int invert_exp_1 (rtx, rtx);
+static int invert_exp_1 (rtx, rtx_insn *);
 
 /* Worker for rebuild_jump_labels and rebuild_jump_labels_chain.  */
 static void
@@ -360,7 +360,7 @@ mark_all_labels (rtx_insn *f)
to help this function avoid overhead in these cases.  */
 enum rtx_code
 reversed_comparison_code_parts (enum rtx_code code, const_rtx arg0,
-   const_rtx arg1, const_rtx insn)
+   const_rtx arg1, const rtx_insn *insn)
 {
   machine_mode mode;
 
@@ -422,7 +422,7 @@ reversed_comparison_code_parts (enum rtx_code code, 
const_rtx arg0,
   /* These CONST_CAST's are okay because prev_nonnote_insn just
 returns its argument and we assign it to a const_rtx
 variable.  */
-  for (rtx_insn *prev = prev_nonnote_insn (CONST_CAST_RTX (insn));
+  for (rtx_insn 

[PATCH 4/8] make next/prev nondebug_insn take rtx_insn *

2016-09-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-09-13  Trevor Saunders  

* emit-rtl.c (next_nondebug_insn): Change argument type to
rtx_insn *.
(prev_nondebug_insn): Likewise.
* loop-doloop.c (doloop_condition_get): Likewise.
* rtl.h: Adjust prototype.
* cfgloop.h: Likewise.
---
 gcc/cfgloop.h | 2 +-
 gcc/emit-rtl.c| 8 ++--
 gcc/loop-doloop.c | 2 +-
 gcc/rtl.h | 4 ++--
 4 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h
index 5c202eb..0448a61 100644
--- a/gcc/cfgloop.h
+++ b/gcc/cfgloop.h
@@ -371,7 +371,7 @@ extern bool just_once_each_iteration_p (const struct loop 
*, const_basic_block);
 gcov_type expected_loop_iterations_unbounded (const struct loop *,
  bool *read_profile_p = NULL);
 extern unsigned expected_loop_iterations (struct loop *);
-extern rtx doloop_condition_get (rtx);
+extern rtx doloop_condition_get (rtx_insn *);
 
 void mark_loop_for_removal (loop_p);
 
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index cbea214..6051326 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3373,10 +3373,8 @@ prev_nonnote_insn_bb (rtx uncast_insn)
routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-next_nondebug_insn (rtx uncast_insn)
+next_nondebug_insn (rtx_insn *insn)
 {
-  rtx_insn *insn = safe_as_a  (uncast_insn);
-
   while (insn)
 {
   insn = NEXT_INSN (insn);
@@ -3391,10 +3389,8 @@ next_nondebug_insn (rtx uncast_insn)
This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nondebug_insn (rtx uncast_insn)
+prev_nondebug_insn (rtx_insn *insn)
 {
-  rtx_insn *insn = safe_as_a  (uncast_insn);
-
   while (insn)
 {
   insn = PREV_INSN (insn);
diff --git a/gcc/loop-doloop.c b/gcc/loop-doloop.c
index c311516..17a968f 100644
--- a/gcc/loop-doloop.c
+++ b/gcc/loop-doloop.c
@@ -70,7 +70,7 @@ along with GCC; see the file COPYING3.  If not see
if it is not a decrement and branch jump insn.  */
 
 rtx
-doloop_condition_get (rtx doloop_pat)
+doloop_condition_get (rtx_insn *doloop_pat)
 {
   rtx cmp;
   rtx inc;
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 0d121bc..b557ffe 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2838,8 +2838,8 @@ extern rtx_insn *prev_nonnote_insn (rtx_insn *);
 extern rtx_insn *prev_nonnote_insn_bb (rtx);
 extern rtx_insn *next_nonnote_insn (rtx_insn *);
 extern rtx_insn *next_nonnote_insn_bb (rtx_insn *);
-extern rtx_insn *prev_nondebug_insn (rtx);
-extern rtx_insn *next_nondebug_insn (rtx);
+extern rtx_insn *prev_nondebug_insn (rtx_insn *);
+extern rtx_insn *next_nondebug_insn (rtx_insn *);
 extern rtx_insn *prev_nonnote_nondebug_insn (rtx);
 extern rtx_insn *next_nonnote_nondebug_insn (rtx);
 extern rtx_insn *prev_real_insn (rtx);
-- 
2.9.3



[PATCH 2/8] use rtx_insn * more

2016-09-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-09-06  Trevor Saunders  

* config/arc/arc-protos.h (arc_label_align): Change type of
variables from rtx to rtx_insn *.
* config/arc/arc.c (arc_label_align): Likewise.
* config/arm/arm.c (any_sibcall_could_use_r3): Likewise.
* config/bfin/bfin.c (workaround_speculation): Likewise.
* config/c6x/c6x.c (find_next_cycle_insn): Likewise.
(find_last_same_clock): Likewise.
(reorg_split_calls): Likewise.
* config/cris/cris-protos.h (cris_cc0_user_requires_cmp): Likewise.
* config/cris/cris.c (cris_cc0_user_requires_cmp): Likewise.
* config/h8300/h8300-protos.h (same_cmp_preceding_p): Likewise.
(same_cmp_following_p): Likewise.
* config/h8300/h8300.c (same_cmp_preceding_p): Likewise.
(same_cmp_following_p): Likwise.
* config/m32r/m32r.c (m32r_expand_epilogue): Likewise.
* config/nds32/nds32-protos.h (nds32_target_alignment): Likewise.
* config/nds32/nds32.c (nds32_target_alignment): Likewise.
* config/rl78/rl78.c (rl78_alloc_physical_registers_op2):
* Likewise.
(rl78_alloc_physical_registers_cmp): Likewise.
(rl78_alloc_physical_registers_umul): Likewise.
(rl78_calculate_death_notes): Likewise.
* config/s390/s390-protos.h (s390_label_align): Likewise.
* config/s390/s390.c (s390_label_align): Likewise.
* config/sh/sh.c (barrier_align): Likewise.
* config/sparc/sparc-protos.h (emit_cbcond_nop): Likewise.
* config/sparc/sparc.c (sparc_asm_function_epilogue): Likewise.
(emit_cbcond_nop): Likewise.
---
 gcc/config/arc/arc-protos.h |  2 +-
 gcc/config/arc/arc.c|  2 +-
 gcc/config/arm/arm.c|  2 +-
 gcc/config/bfin/bfin.c  |  2 +-
 gcc/config/c6x/c6x.c| 19 +--
 gcc/config/cris/cris-protos.h   |  2 +-
 gcc/config/cris/cris.c  |  2 +-
 gcc/config/h8300/h8300-protos.h |  4 ++--
 gcc/config/h8300/h8300.c|  4 ++--
 gcc/config/m32r/m32r.c  |  2 +-
 gcc/config/nds32/nds32-protos.h |  2 +-
 gcc/config/nds32/nds32.c|  2 +-
 gcc/config/rl78/rl78.c  | 11 ++-
 gcc/config/s390/s390-protos.h   |  2 +-
 gcc/config/s390/s390.c  |  2 +-
 gcc/config/sh/sh.c  |  2 +-
 gcc/config/sparc/sparc-protos.h |  2 +-
 gcc/config/sparc/sparc.c|  8 +++-
 18 files changed, 35 insertions(+), 37 deletions(-)

diff --git a/gcc/config/arc/arc-protos.h b/gcc/config/arc/arc-protos.h
index 8630e2d..73aacbc 100644
--- a/gcc/config/arc/arc-protos.h
+++ b/gcc/config/arc/arc-protos.h
@@ -109,7 +109,7 @@ extern rtx arc_regno_use_in (unsigned int, rtx);
 extern int arc_attr_type (rtx_insn *);
 extern bool arc_scheduling_not_expected (void);
 extern bool arc_sets_cc_p (rtx_insn *insn);
-extern int arc_label_align (rtx label);
+extern int arc_label_align (rtx_insn *label);
 extern bool arc_need_delay (rtx_insn *insn);
 extern bool arc_text_label (rtx_insn *insn);
 
diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index c0aa075..2b25b0b 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -9243,7 +9243,7 @@ arc_scheduling_not_expected (void)
long.)  */
 
 int
-arc_label_align (rtx label)
+arc_label_align (rtx_insn *label)
 {
   int loop_align = LOOP_ALIGN (LABEL);
 
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 43a832e..63d0067 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -20860,7 +20860,7 @@ any_sibcall_could_use_r3 (void)
   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
 if (e->flags & EDGE_SIBCALL)
   {
-   rtx call = BB_END (e->src);
+   rtx_insn *call = BB_END (e->src);
if (!CALL_P (call))
  call = prev_nonnote_nondebug_insn (call);
gcc_assert (CALL_P (call) && SIBLING_CALL_P (call));
diff --git a/gcc/config/bfin/bfin.c b/gcc/config/bfin/bfin.c
index 086d548..4683a28 100644
--- a/gcc/config/bfin/bfin.c
+++ b/gcc/config/bfin/bfin.c
@@ -4452,7 +4452,7 @@ workaround_speculation (void)
  || cbranch_predicted_taken_p (insn)))
{
  rtx_insn *target = JUMP_LABEL_AS_INSN (insn);
- rtx label = target;
+ rtx_insn *label = target;
  rtx_insn *next_tgt;
 
  cycles_since_jump = 0;
diff --git a/gcc/config/c6x/c6x.c b/gcc/config/c6x/c6x.c
index d759482..c250f8a 100644
--- a/gcc/config/c6x/c6x.c
+++ b/gcc/config/c6x/c6x.c
@@ -4807,10 +4807,10 @@ convert_to_callp (rtx_insn *insn)
 /* Scan forwards from INSN until we find the next insn that has mode TImode
(indicating it starts a new cycle), and occurs in cycle CLOCK.
Return it if we find such an insn, NULL_RTX otherwise.  */
-static rtx
-find_next_cycle_insn (rtx insn, int clock)
+static rtx_insn *
+find_next_cycle_insn (rtx_insn *insn, int clock)
 {
-  rtx t = insn;
+  rtx_insn *t = insn;
   if 

[PATCH 1/8] change a few rtx_insn * to rtx_jump_insn *

2016-09-14 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-09-06  Trevor Saunders  

* bb-reorder.c (fix_crossing_unconditional_branches): Make type
of jump_insn rtx_jump_insn *.
* reorg.c (steal_delay_list_from_target): Make type of insn
rtx_jump_insn *.
(follow_jumps): Make type of jump rtx_jump_insn *.
---
 gcc/bb-reorder.c |  5 ++---
 gcc/reorg.c  | 12 ++--
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/gcc/bb-reorder.c b/gcc/bb-reorder.c
index bb8435f..b26c041 100644
--- a/gcc/bb-reorder.c
+++ b/gcc/bb-reorder.c
@@ -2146,7 +2146,7 @@ fix_crossing_unconditional_branches (void)
   rtx label;
   rtx label_addr;
   rtx_insn *indirect_jump_sequence;
-  rtx_insn *jump_insn = NULL;
+  rtx_jump_insn *jump_insn = NULL;
   rtx new_reg;
   rtx_insn *cur_insn;
   edge succ;
@@ -2201,8 +2201,7 @@ fix_crossing_unconditional_branches (void)
{
  if (!BARRIER_P (cur_insn))
BLOCK_FOR_INSN (cur_insn) = cur_bb;
- if (JUMP_P (cur_insn))
-   jump_insn = cur_insn;
+ jump_insn = dyn_cast (cur_insn);
}
 
  /* Insert the new (indirect) jump sequence immediately before
diff --git a/gcc/reorg.c b/gcc/reorg.c
index c58d608..d798c6a 100644
--- a/gcc/reorg.c
+++ b/gcc/reorg.c
@@ -205,7 +205,7 @@ static int redirect_with_delay_slots_safe_p (rtx_insn *, 
rtx, rtx);
 static int redirect_with_delay_list_safe_p (rtx_insn *, rtx,
const vec &);
 static int check_annul_list_true_false (int, const vec &);
-static void steal_delay_list_from_target (rtx_insn *, rtx, rtx_sequence *,
+static void steal_delay_list_from_target (rtx_jump_insn *, rtx, rtx_sequence *,
  vec *,
  struct resources *,
  struct resources *,
@@ -1033,10 +1033,10 @@ check_annul_list_true_false (int annul_true_p,
execution should continue.  */
 
 static void
-steal_delay_list_from_target (rtx_insn *insn, rtx condition, rtx_sequence *seq,
- vec *delay_list, resources *sets,
- struct resources *needed,
- struct resources *other_needed,
+steal_delay_list_from_target (rtx_jump_insn *insn, rtx condition,
+ rtx_sequence *seq, vec *delay_list,
+ resources *sets, resources *needed,
+ resources *other_needed,
  int slots_to_fill, int *pslots_filled,
  int *pannul_p, rtx *pnew_thread)
 {
@@ -2265,7 +2265,7 @@ fill_simple_delay_slots (int non_jumps_p)
set *CROSSING to true, otherwise set it to false.  */
 
 static rtx
-follow_jumps (rtx label, rtx_insn *jump, bool *crossing)
+follow_jumps (rtx label, rtx_jump_insn *jump, bool *crossing)
 {
   rtx_insn *insn;
   rtx_insn *next;
-- 
2.9.3



[PATCH 0/8] make next_*_insn take rtx_insn * arguments

2016-09-14 Thread tbsaunde+gcc
From: Trevor Saunders 

Hi,

Basically $subject.  First change variable's type to rtx_insn * where possible.
Then change the functions and fixup callers where it is still necessary to
cast.

patches bootstrapped and regtested individually on x86_64-linux-gnu, and the
series was run through config-list.mk, ok?

Trev

Trevor Saunders (8):
  change a few rtx_insn * to rtx_jump_insn *
  use rtx_insn * more
  make next/prev _nonnote_insn take rtx_insn *
  make next/prev nondebug_insn take rtx_insn *
  make prev_real_insn take rtx_insn *
  make next/prev nonnote_nondebug_insn take rtx_insn *
  make next/prev active_insn and active_insn_p take rtx_insn *
  make next_cc0_user take rtx_insn *

 gcc/bb-reorder.c|  5 ++--
 gcc/cfgcleanup.c|  2 +-
 gcc/cfgloop.h   |  2 +-
 gcc/config/arc/arc-protos.h |  2 +-
 gcc/config/arc/arc.c|  2 +-
 gcc/config/arc/arc.md   | 43 +++-
 gcc/config/arm/arm.c|  2 +-
 gcc/config/bfin/bfin.c  |  2 +-
 gcc/config/c6x/c6x.c| 19 ++---
 gcc/config/cris/cris-protos.h   |  4 +--
 gcc/config/cris/cris.c  | 14 -
 gcc/config/h8300/h8300-protos.h |  4 +--
 gcc/config/h8300/h8300.c|  4 +--
 gcc/config/m32r/m32r.c  |  2 +-
 gcc/config/nds32/nds32-protos.h |  2 +-
 gcc/config/nds32/nds32.c|  2 +-
 gcc/config/pa/pa.c  |  6 ++--
 gcc/config/rl78/rl78.c  | 11 +++
 gcc/config/s390/s390-protos.h   |  2 +-
 gcc/config/s390/s390.c  |  2 +-
 gcc/config/sh/sh.c  | 10 +++
 gcc/config/sh/sh.md |  3 +-
 gcc/config/sparc/sparc-protos.h |  2 +-
 gcc/config/sparc/sparc.c|  8 ++
 gcc/cse.c   |  2 +-
 gcc/dwarf2out.c |  2 +-
 gcc/emit-rtl.c  | 41 +++
 gcc/jump.c  | 18 ++--
 gcc/loop-doloop.c   |  2 +-
 gcc/reorg.c | 63 ++---
 gcc/resource.c  |  2 +-
 gcc/rtl.h   | 26 -
 gcc/simplify-rtx.c  |  8 +++---
 33 files changed, 160 insertions(+), 159 deletions(-)

-- 
2.9.3



[PATCH 0/3] more rtl list work

2016-08-25 Thread tbsaunde+gcc
From: Trevor Saunders 

Hi,

continueing on with getting rid of uses of rtx_insn_list and rtx_expr_list.

bootstrapped + regtested patches individually on x86_64-linux-gnu, ok?

Thanks!

Trev


Trevor Saunders (3):
  haifa-sched.c: make ready_list an auto_vec
  make forced labels a vec
  make stack_slot_list a vec

 gcc/cfgbuild.c|  9 ++---
 gcc/cfgrtl.c  |  3 ++-
 gcc/dwarf2cfi.c   |  6 --
 gcc/emit-rtl.c| 11 ---
 gcc/emit-rtl.h|  2 +-
 gcc/except.c  |  3 +--
 gcc/function.c|  8 +++-
 gcc/function.h|  2 +-
 gcc/haifa-sched.c | 12 ++--
 gcc/jump.c| 12 +++-
 gcc/reload1.c |  7 ---
 gcc/stmt.c|  4 ++--
 12 files changed, 45 insertions(+), 34 deletions(-)

-- 
2.9.0



[PATCH 2/3] make forced labels a vec

2016-08-25 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-08-25  Trevor Saunders  

* cfgbuild.c (make_edges): Adjust.
* cfgrtl.c (can_delete_label_p): Likewise.
* dwarf2cfi.c (create_trace_edges): Likewise.
* except.c (sjlj_emit_dispatch_table): Likewise.
* function.h (struct expr_status): make x_forced_labels a vector.
* jump.c (rebuild_jump_labels_1): Adjust.
* reload1.c (set_initial_label_offsets): Likewise.
* stmt.c (force_label_rtx): Likewise.
(expand_label): Likewise.
---
 gcc/cfgbuild.c  |  9 ++---
 gcc/cfgrtl.c|  3 ++-
 gcc/dwarf2cfi.c |  6 --
 gcc/except.c|  3 +--
 gcc/function.h  |  2 +-
 gcc/jump.c  | 12 +++-
 gcc/reload1.c   |  7 ---
 gcc/stmt.c  |  4 ++--
 8 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/gcc/cfgbuild.c b/gcc/cfgbuild.c
index c1ec46a..20fc270 100644
--- a/gcc/cfgbuild.c
+++ b/gcc/cfgbuild.c
@@ -204,7 +204,8 @@ make_edges (basic_block min, basic_block max, int update_p)
   /* Heavy use of computed goto in machine-generated code can lead to
  nearly fully-connected CFGs.  In that case we spend a significant
  amount of time searching the edge lists for duplicates.  */
-  if (forced_labels || cfun->cfg->max_jumptable_ents > 100)
+  if (!vec_safe_is_empty (forced_labels)
+  || cfun->cfg->max_jumptable_ents > 100)
 edge_cache = sbitmap_alloc (last_basic_block_for_fn (cfun));
 
   /* By nature of the way these get numbered, ENTRY_BLOCK_PTR->next_bb block
@@ -280,8 +281,10 @@ make_edges (basic_block min, basic_block max, int update_p)
 everything on the forced_labels list.  */
  else if (computed_jump_p (insn))
{
- for (rtx_insn_list *x = forced_labels; x; x = x->next ())
-   make_label_edge (edge_cache, bb, x->insn (), EDGE_ABNORMAL);
+ rtx_insn *insn;
+ unsigned int i;
+ FOR_EACH_VEC_SAFE_ELT_REVERSE (forced_labels, i, insn)
+   make_label_edge (edge_cache, bb, insn, EDGE_ABNORMAL);
}
 
  /* Returns create an exit out.  */
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index 0d335fc..de07fcd 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -115,7 +115,8 @@ can_delete_label_p (const rtx_code_label *label)
   return (!LABEL_PRESERVE_P (label)
  /* User declared labels must be preserved.  */
  && LABEL_NAME (label) == 0
- && !in_insn_list_p (forced_labels, label));
+ && !vec_safe_contains (forced_labels,
+const_cast 
(label)));
 }
 
 /* Delete INSN by patching it out.  */
diff --git a/gcc/dwarf2cfi.c b/gcc/dwarf2cfi.c
index bcf79f5..3ded2ce 100644
--- a/gcc/dwarf2cfi.c
+++ b/gcc/dwarf2cfi.c
@@ -2354,8 +2354,10 @@ create_trace_edges (rtx_insn *insn)
}
   else if (computed_jump_p (insn))
{
- for (rtx_insn_list *lab = forced_labels; lab; lab = lab->next ())
-   maybe_record_trace_start (lab->insn (), insn);
+ rtx_insn *temp;
+ unsigned int i;
+ FOR_EACH_VEC_SAFE_ELT_REVERSE (forced_labels, i, temp)
+   maybe_record_trace_start (temp, insn);
}
   else if (returnjump_p (insn))
;
diff --git a/gcc/except.c b/gcc/except.c
index 8aeb4e8..bc6f30c 100644
--- a/gcc/except.c
+++ b/gcc/except.c
@@ -1278,8 +1278,7 @@ sjlj_emit_dispatch_table (rtx_code_label *dispatch_label, 
int num_dispatch)
  label on the nonlocal_goto_label list.  Since we're modeling these
  CFG edges more exactly, we can use the forced_labels list instead.  */
   LABEL_PRESERVE_P (dispatch_label) = 1;
-  forced_labels
-= gen_rtx_INSN_LIST (VOIDmode, dispatch_label, forced_labels);
+  vec_safe_push (forced_labels, dispatch_label);
 #endif
 
   /* Load up exc_ptr and filter values from the function context.  */
diff --git a/gcc/function.h b/gcc/function.h
index 501ef68..590a490 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -126,7 +126,7 @@ struct GTY(()) expr_status {
   rtx x_apply_args_value;
 
   /* List of labels that must never be deleted.  */
-  rtx_insn_list *x_forced_labels;
+  vec *x_forced_labels;
 };
 
 typedef struct call_site_record_d *call_site_record;
diff --git a/gcc/jump.c b/gcc/jump.c
index 5b433af..b166926 100644
--- a/gcc/jump.c
+++ b/gcc/jump.c
@@ -68,8 +68,6 @@ static int invert_exp_1 (rtx, rtx);
 static void
 rebuild_jump_labels_1 (rtx_insn *f, bool count_forced)
 {
-  rtx_insn_list *insn;
-
   timevar_push (TV_REBUILD_JUMP);
   init_label_info (f);
   mark_all_labels (f);
@@ -79,9 +77,13 @@ rebuild_jump_labels_1 (rtx_insn *f, bool count_forced)
  count doesn't drop to zero.  */
 
   if (count_forced)
-for (insn = forced_labels; insn; insn = insn->next ())
-  if (LABEL_P (insn->insn ()))
-   LABEL_NUSES (insn->insn ())++;
+{
+  rtx_insn *insn;
+  unsigned int i;
+  FOR_EACH_VEC_SAFE_ELT_REVERSE 

[PATCH 3/3] make stack_slot_list a vec

2016-08-25 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-08-25  Trevor Saunders  

* emit-rtl.h (struct rtl_data): Make stack_slot_list a vector.
* emit-rtl.c (unshare_all_rtl_1): Adjust.
(unshare_all_rtl_again): Likewise.
* function.c (assign_stack_local_1): Likewise.
(assign_stack_temp_for_type): Likewise.
---
 gcc/emit-rtl.c | 11 ---
 gcc/emit-rtl.h |  2 +-
 gcc/function.c |  8 +++-
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 99f052d..c1051eb 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -2626,8 +2626,10 @@ unshare_all_rtl_1 (rtx_insn *insn)
  This special care is necessary when the stack slot MEM does not
  actually appear in the insn chain.  If it does appear, its address
  is unshared from all else at that point.  */
-  stack_slot_list = safe_as_a  (
- copy_rtx_if_shared (stack_slot_list));
+  unsigned int i;
+  rtx temp;
+  FOR_EACH_VEC_SAFE_ELT_REVERSE (stack_slot_list, i, temp)
+(*stack_slot_list)[i] = copy_rtx_if_shared (temp);
 }
 
 /* Go through all the RTL insn bodies and copy any invalid shared
@@ -2656,7 +2658,10 @@ unshare_all_rtl_again (rtx_insn *insn)
   for (decl = DECL_ARGUMENTS (cfun->decl); decl; decl = DECL_CHAIN (decl))
 set_used_flags (DECL_RTL (decl));
 
-  reset_used_flags (stack_slot_list);
+  rtx temp;
+  unsigned int i;
+  FOR_EACH_VEC_SAFE_ELT_REVERSE (stack_slot_list, i, temp)
+reset_used_flags (temp);
 
   unshare_all_rtl_1 (insn);
 }
diff --git a/gcc/emit-rtl.h b/gcc/emit-rtl.h
index 39dfce9..52c72b1 100644
--- a/gcc/emit-rtl.h
+++ b/gcc/emit-rtl.h
@@ -104,7 +104,7 @@ struct GTY(()) rtl_data {
 
   /* List (chain of EXPR_LISTs) of all stack slots in this function.
  Made for the sake of unshare_all_rtl.  */
-  rtx_expr_list *x_stack_slot_list;
+  vec *x_stack_slot_list;
 
   /* List of empty areas in the stack frame.  */
   struct frame_space *frame_space_list;
diff --git a/gcc/function.c b/gcc/function.c
index bba0705..53bad87 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -499,8 +499,7 @@ assign_stack_local_1 (machine_mode mode, HOST_WIDE_INT size,
   set_mem_align (x, alignment_in_bits);
   MEM_NOTRAP_P (x) = 1;
 
-  stack_slot_list
-= gen_rtx_EXPR_LIST (VOIDmode, x, stack_slot_list);
+  vec_safe_push (stack_slot_list, x);
 
   if (frame_offset_overflow (frame_offset, current_function_decl))
 frame_offset = 0;
@@ -829,8 +828,7 @@ assign_stack_temp_for_type (machine_mode mode, 
HOST_WIDE_INT size,
  p->type = best_p->type;
  insert_slot_to_list (p, _temp_slots);
 
- stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
-  stack_slot_list);
+ vec_safe_push (stack_slot_list, p->slot);
 
  best_p->size = rounded_size;
  best_p->full_size = rounded_size;
@@ -902,7 +900,7 @@ assign_stack_temp_for_type (machine_mode mode, 
HOST_WIDE_INT size,
 
   /* Create a new MEM rtx to avoid clobbering MEM flags of old slots.  */
   slot = gen_rtx_MEM (mode, XEXP (p->slot, 0));
-  stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, slot, stack_slot_list);
+  vec_safe_push (stack_slot_list, slot);
 
   /* If we know the alias set for the memory that will be used, use
  it.  If there's no TYPE, then we don't know anything about the
-- 
2.9.0



[PATCH 1/3] haifa-sched.c: make ready_list an auto_vec

2016-08-25 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-08-25  Trevor Saunders  

* haifa-sched.c (fix_recovery_deps): Make ready_list a vector.
---
 gcc/haifa-sched.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c
index 84e42c0..c58b0ad 100644
--- a/gcc/haifa-sched.c
+++ b/gcc/haifa-sched.c
@@ -8600,9 +8600,8 @@ static void
 fix_recovery_deps (basic_block rec)
 {
   rtx_insn *note, *insn, *jump;
-  rtx_insn_list *ready_list = 0;
+  auto_vec ready_list;
   bitmap_head in_ready;
-  rtx_insn_list *link;
 
   bitmap_initialize (_ready, 0);
 
@@ -8628,7 +8627,7 @@ fix_recovery_deps (basic_block rec)
  sd_delete_dep (sd_it);
 
  if (bitmap_set_bit (_ready, INSN_LUID (consumer)))
-   ready_list = alloc_INSN_LIST (consumer, ready_list);
+   ready_list.safe_push (consumer);
}
  else
{
@@ -8645,9 +8644,10 @@ fix_recovery_deps (basic_block rec)
   bitmap_clear (_ready);
 
   /* Try to add instructions to the ready or queue list.  */
-  for (link = ready_list; link; link = link->next ())
-try_ready (link->insn ());
-  free_INSN_LIST_list (_list);
+  unsigned int i;
+  rtx_insn *temp;
+  FOR_EACH_VEC_ELT_REVERSE (ready_list, i, temp)
+try_ready (temp);
 
   /* Fixing jump's dependences.  */
   insn = BB_HEAD (rec);
-- 
2.9.0



[PATCH] remove HARD_FRAME_POINTER_IS_ARG_POINTER macro

2016-08-20 Thread tbsaunde+gcc
From: Trevor Saunders 

Hi,

its kind of silly, and this allows us to remove a few more #ifdefs.

bootstrapped + regtest x86_64-linux-gnu, ok?

Trev

gcc/ChangeLog:

2016-08-20  Trevor Saunders  

* rtl.h (HARD_FRAME_POINTER_IS_ARG_POINTER): Remove definition.
(enum global_rtl_index): Adjust.
* builtins.c (expand_builtin_setjmp_receiver): Likewise.
* config/arm/arm.h: Likewise.
* config/mips/mips.h: Likewise.
* dbxout.c (dbxout_symbol_location): Likewise.
(dbxout_parms): Likewise.
* doc/tm.texi: Regenerate.
* doc/tm.texi.in: Adjust.
* dse.c (scan_insn): Likewise.
* dwarf2out.c (rtl_for_decl_location): Likewise.
* emit-rtl.c (gen_rtx_REG): Likewise.
---
 gcc/builtins.c |  3 ++-
 gcc/config/arm/arm.h   |  1 -
 gcc/config/mips/mips.h |  1 -
 gcc/dbxout.c   | 10 ++
 gcc/doc/tm.texi|  8 
 gcc/doc/tm.texi.in |  8 
 gcc/dse.c  |  2 +-
 gcc/dwarf2out.c|  5 +
 gcc/emit-rtl.c |  7 ---
 gcc/rtl.h  |  7 +--
 10 files changed, 11 insertions(+), 41 deletions(-)

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 03a0dc8..657fb74 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -859,7 +859,8 @@ expand_builtin_setjmp_receiver (rtx receiver_label)
   emit_clobber (hard_frame_pointer_rtx);
 }
 
-  if (!HARD_FRAME_POINTER_IS_ARG_POINTER && fixed_regs[ARG_POINTER_REGNUM])
+  if (HARD_FRAME_POINTER_REGNUM!= ARG_POINTER_REGNUM
+  && fixed_regs[ARG_POINTER_REGNUM])
 {
 #ifdef ELIMINABLE_REGS
   /* If the argument pointer can be eliminated in favor of the
diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index c7149d1..352d859 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -916,7 +916,6 @@ extern int arm_arch_crc;
: THUMB_HARD_FRAME_POINTER_REGNUM)
 
 #define HARD_FRAME_POINTER_IS_FRAME_POINTER 0
-#define HARD_FRAME_POINTER_IS_ARG_POINTER 0
 
 #define FP_REGNUM  HARD_FRAME_POINTER_REGNUM
 
diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h
index e8897d1..7b71fe3 100644
--- a/gcc/config/mips/mips.h
+++ b/gcc/config/mips/mips.h
@@ -1967,7 +1967,6 @@ FP_ASM_SPEC "\
   (TARGET_MIPS16 ? GP_REG_FIRST + 17 : GP_REG_FIRST + 30)
 
 #define HARD_FRAME_POINTER_IS_FRAME_POINTER 0
-#define HARD_FRAME_POINTER_IS_ARG_POINTER 0
 
 /* Register in which static-chain is passed to a function.  */
 #define STATIC_CHAIN_REGNUM (GP_REG_FIRST + 15)
diff --git a/gcc/dbxout.c b/gcc/dbxout.c
index ad256c7..9d6ecf3 100644
--- a/gcc/dbxout.c
+++ b/gcc/dbxout.c
@@ -3078,10 +3078,7 @@ dbxout_symbol_location (tree decl, tree type, const char 
*suffix, rtx home)
   || (REG_P (XEXP (home, 0))
   && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
   && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
-#if !HARD_FRAME_POINTER_IS_ARG_POINTER
-  && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
-#endif
-  )))
+  && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM)))
 /* If the value is indirect by memory or by a register
that isn't the frame pointer
then it means the object is variable-sized and address through
@@ -3492,10 +3489,7 @@ dbxout_parms (tree parms)
 && REG_P (XEXP (DECL_RTL (parms), 0))
 && REGNO (XEXP (DECL_RTL (parms), 0)) != 
HARD_FRAME_POINTER_REGNUM
 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
-#if !HARD_FRAME_POINTER_IS_ARG_POINTER
-&& REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
-#endif
-)
+&& REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM)
  {
/* Parm was passed via invisible reference.
   That is, its address was passed in a register.
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 9edb006..129ca82 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -3472,14 +3472,6 @@ the same.  The default definition is 
@samp{(HARD_FRAME_POINTER_REGNUM
 definition is not suitable for use in preprocessor conditionals.
 @end defmac
 
-@defmac HARD_FRAME_POINTER_IS_ARG_POINTER
-Define this to a preprocessor constant that is nonzero if
-@code{hard_frame_pointer_rtx} and @code{arg_pointer_rtx} should be the
-same.  The default definition is @samp{(HARD_FRAME_POINTER_REGNUM ==
-ARG_POINTER_REGNUM)}; you only need to define this macro if that
-definition is not suitable for use in preprocessor conditionals.
-@end defmac
-
 @defmac RETURN_ADDRESS_POINTER_REGNUM
 The register number of the return address pointer register, which is used to
 access the current function's return address from the stack.  On some
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index a72c3d8..0adde80 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -3058,14 +3058,6 @@ 

[PATCH] remove conditional compilation of HAVE_AS_LEB128 code

2016-08-20 Thread tbsaunde+gcc
From: Trevor Saunders 

Hi,

basically just $subject, always define HAVE_AS_LEB128, and then use if / else
instead of #ifdef.  Note the diff has a bit of whitespace noise, so there's a 
-w diff below the full one.

bootstrapped and regtested on x86_64-linux-gnu, ok?

Trev

gcc/ChangeLog:

2016-08-20  Trevor Saunders  

* acinclude.m4 (gcc_GAS_CHECK_FEATURE): Support doing an action
if the feature isn't available.
* configure: Regenerate.
* configure.ac: define HAVE_AS_LEB128 to 0 when not available.
* dwarf2asm.c (dw2_asm_output_data_uleb128): Always compile code
for HAVE_AS_LEB128.
(dw2_asm_output_data_sleb128): Likewise.
(dw2_asm_output_delta_uleb128): Likewise.
(dw2_asm_output_delta_sleb128): Likewise.
* except.c (output_one_function_exception_table): Likewise.
(dw2_size_of_call_site_table): Likewise.
(sjlj_size_of_call_site_table): Likewise.
---
 gcc/acinclude.m4 |   4 ++
 gcc/configure| 106 +++-
 gcc/configure.ac |   2 +
 gcc/dwarf2asm.c  | 184 +++
 gcc/except.c | 162 
 5 files changed, 283 insertions(+), 175 deletions(-)

diff --git a/gcc/acinclude.m4 b/gcc/acinclude.m4
index 38dd899..791f2a7 100644
--- a/gcc/acinclude.m4
+++ b/gcc/acinclude.m4
@@ -550,6 +550,10 @@ AC_CACHE_CHECK([assembler for $1], [$2],
 ifelse([$7],,,[dnl
 if test $[$2] = yes; then
   $7
+fi])
+ifelse([$8],,,[dnl
+if test $[$2] != yes; then
+  $8
 fi])])
 
 dnl gcc_SUN_LD_VERSION
diff --git a/gcc/configure b/gcc/configure
index 871ed0c..e286123 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -22485,6 +22485,7 @@ $as_echo "#define HAVE_GAS_BALIGN_AND_P2ALIGN 1" 
>>confdefs.h
 
 fi
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .p2align with 
maximum skip" >&5
 $as_echo_n "checking assembler for .p2align with maximum skip... " >&6; }
 if test "${gcc_cv_as_max_skip_p2align+set}" = set; then :
@@ -22520,6 +22521,7 @@ $as_echo "#define HAVE_GAS_MAX_SKIP_P2ALIGN 1" 
>>confdefs.h
 
 fi
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .literal16" >&5
 $as_echo_n "checking assembler for .literal16... " >&6; }
 if test "${gcc_cv_as_literal16+set}" = set; then :
@@ -22555,6 +22557,7 @@ $as_echo "#define HAVE_GAS_LITERAL16 1" >>confdefs.h
 
 fi
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for working 
.subsection -1" >&5
 $as_echo_n "checking assembler for working .subsection -1... " >&6; }
 if test "${gcc_cv_as_subsection_m1+set}" = set; then :
@@ -22602,6 +22605,7 @@ $as_echo "#define HAVE_GAS_SUBSECTION_ORDERING 1" 
>>confdefs.h
 
 fi
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .weak" >&5
 $as_echo_n "checking assembler for .weak... " >&6; }
 if test "${gcc_cv_as_weak+set}" = set; then :
@@ -22637,6 +22641,7 @@ $as_echo "#define HAVE_GAS_WEAK 1" >>confdefs.h
 
 fi
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .weakref" >&5
 $as_echo_n "checking assembler for .weakref... " >&6; }
 if test "${gcc_cv_as_weakref+set}" = set; then :
@@ -22672,6 +22677,7 @@ $as_echo "#define HAVE_GAS_WEAKREF 1" >>confdefs.h
 
 fi
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .nsubspa 
comdat" >&5
 $as_echo_n "checking assembler for .nsubspa comdat... " >&6; }
 if test "${gcc_cv_as_nsubspa_comdat+set}" = set; then :
@@ -22708,6 +22714,7 @@ $as_echo "#define HAVE_GAS_NSUBSPA_COMDAT 1" 
>>confdefs.h
 
 fi
 
+
 # .hidden needs to be supported in both the assembler and the linker,
 # because GNU LD versions before 2.12.1 have buggy support for STV_HIDDEN.
 # This is irritatingly difficult to feature test for; we have to check the
@@ -22747,6 +22754,7 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_hidden" >&5
 $as_echo "$gcc_cv_as_hidden" >&6; }
 
+
 case "${target}" in
   *-*-darwin*)
 # Darwin as has some visibility support, though with a different syntax.
@@ -23199,6 +23207,11 @@ if test $gcc_cv_as_leb128 = yes; then
 $as_echo "#define HAVE_AS_LEB128 1" >>confdefs.h
 
 fi
+if test $gcc_cv_as_leb128 != yes; then
+
+$as_echo "#define HAVE_AS_LEB128 0" >>confdefs.h
+
+fi
 
 # Check if we have assembler support for unwind directives.
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for cfi 
directives" >&5
@@ -23278,6 +23291,7 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_cfi_directive" >&5
 $as_echo "$gcc_cv_as_cfi_directive" >&6; }
 
+
 if test $gcc_cv_as_cfi_directive = yes && test x$gcc_cv_objdump != x; then
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for working cfi 
advance" >&5
 $as_echo_n "checking assembler for working cfi advance... " >&6; }
@@ -23315,6 +23329,7 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$gcc_cv_as_cfi_advance_working" >&5
 $as_echo 

[PATCH 3/3] merge adjust_cost and adjust_cost_2 target hooks

2016-07-24 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-07-24  Trevor Saunders  

* config/alpha/alpha.c (alpha_adjust_cost): Adjust.
* config/arm/arm-protos.h (struct tune_params): Likewise.
* config/arm/arm.c (xscale_sched_adjust_cost): Likewise.
(cortex_a9_sched_adjust_cost): Likewise.
(fa726te_sched_adjust_cost): Likewise.
(arm_adjust_cost): Likewise.
* config/bfin/bfin.c (bfin_adjust_cost): Likewise.
* config/c6x/c6x.c (c6x_adjust_cost): Likewise.
* config/epiphany/epiphany.c (epiphany_adjust_cost): Likewise.
* config/i386/i386.c (ix86_adjust_cost): Likewise.
* config/ia64/ia64.c: Likewise.
* config/m68k/m68k.c: Likewise.
* config/mep/mep.c (mep_adjust_cost): Likewise.
* config/microblaze/microblaze.c (microblaze_adjust_cost):
* Likewise.
* config/mips/mips.c (mips_adjust_cost): Likewise.
* config/mn10300/mn10300.c (mn10300_adjust_sched_cost):
* Likewise.
* config/pa/pa.c (pa_adjust_cost): Likewise.
* config/rs6000/rs6000.c (rs6000_adjust_cost): Likewise.
(rs6000_debug_adjust_cost): Likewise.
* config/sh/sh.c (sh_adjust_cost): Likewise.
* config/sparc/sparc.c (supersparc_adjust_cost): Likewise.
(hypersparc_adjust_cost): Likewise.
(sparc_adjust_cost): Likewise.
* config/spu/spu.c (spu_sched_adjust_cost): Likewise.
* config/tilegx/tilegx.c (tilegx_sched_adjust_cost): Likewise.
* config/tilepro/tilepro.c (tilepro_sched_adjust_cost):
* Likewise.
* config/visium/visium.c (visium_adjust_cost): Likewise.
* doc/tm.texi: Regenerate.
* haifa-sched.c (dep_cost_1): Adjust.
* target.def: Merge adjust_cost and adjust_cost_2.
---
 gcc/config/alpha/alpha.c   |  5 +++--
 gcc/config/arm/arm-protos.h|  2 +-
 gcc/config/arm/arm.c   | 40 +-
 gcc/config/bfin/bfin.c |  5 +++--
 gcc/config/c6x/c6x.c   |  5 +++--
 gcc/config/epiphany/epiphany.c |  5 +++--
 gcc/config/i386/i386.c |  5 +++--
 gcc/config/ia64/ia64.c | 10 +-
 gcc/config/m68k/m68k.c |  7 ---
 gcc/config/microblaze/microblaze.c | 10 --
 gcc/config/mips/mips.c |  8 ++--
 gcc/config/mn10300/mn10300.c   |  5 +++--
 gcc/config/pa/pa.c |  9 +
 gcc/config/rs6000/rs6000.c | 16 ---
 gcc/config/sh/sh.c | 10 +-
 gcc/config/sparc/sparc.c   | 23 --
 gcc/config/spu/spu.c   |  5 +++--
 gcc/config/tilegx/tilegx.c |  6 +++---
 gcc/config/tilepro/tilepro.c   |  6 +++---
 gcc/config/visium/visium.c | 11 ++-
 gcc/doc/tm.texi| 14 ++---
 gcc/haifa-sched.c  | 25 +++-
 gcc/target.def | 25 +---
 23 files changed, 122 insertions(+), 135 deletions(-)

diff --git a/gcc/config/alpha/alpha.c b/gcc/config/alpha/alpha.c
index 94fed102..702cd27 100644
--- a/gcc/config/alpha/alpha.c
+++ b/gcc/config/alpha/alpha.c
@@ -4758,14 +4758,15 @@ alpha_split_atomic_exchange_12 (rtx operands[])
a dependency LINK or INSN on DEP_INSN.  COST is the current cost.  */
 
 static int
-alpha_adjust_cost (rtx_insn *insn, rtx link, rtx_insn *dep_insn, int cost)
+alpha_adjust_cost (rtx_insn *insn, int dep_type, rtx_insn *dep_insn, int cost,
+  unsigned int)
 {
   enum attr_type dep_insn_type;
 
   /* If the dependence is an anti-dependence, there is no cost.  For an
  output dependence, there is sometimes a cost, but it doesn't seem
  worth handling those few cases.  */
-  if (REG_NOTE_KIND (link) != 0)
+  if (dep_type != 0)
 return cost;
 
   /* If we can't recognize the insns, we can't really do anything.  */
diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h
index 49c3a92..3975612 100644
--- a/gcc/config/arm/arm-protos.h
+++ b/gcc/config/arm/arm-protos.h
@@ -260,7 +260,7 @@ struct tune_params
 {
   bool (*rtx_costs) (rtx, RTX_CODE, RTX_CODE, int *, bool);
   const struct cpu_cost_table *insn_extra_cost;
-  bool (*sched_adjust_cost) (rtx_insn *, rtx, rtx_insn *, int *);
+  bool (*sched_adjust_cost) (rtx_insn *, int, rtx_insn *, int *);
   int (*branch_cost) (bool, bool);
   /* Vectorizer costs.  */
   const struct cpu_vec_costs* vec_costs;
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 195de48..a6afdcc 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -138,7 +138,7 @@ static void arm_output_function_epilogue (FILE *, 
HOST_WIDE_INT);
 static void arm_output_function_prologue (FILE *, HOST_WIDE_INT);
 static int arm_comp_type_attributes (const_tree, const_tree);
 static void arm_set_default_type_attributes (tree);
-static int 

[PATCH 2/3] haifa-sched.c: make twins a auto_vec

2016-07-24 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-07-24  Trevor Saunders  

* haifa-sched.c (add_to_speculative_block): Make twins a vector.
---
 gcc/haifa-sched.c | 25 -
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c
index 9503576..93b7089 100644
--- a/gcc/haifa-sched.c
+++ b/gcc/haifa-sched.c
@@ -7991,7 +7991,7 @@ add_to_speculative_block (rtx_insn *insn)
   ds_t ts;
   sd_iterator_def sd_it;
   dep_t dep;
-  rtx_insn_list *twins = NULL;
+  auto_vec twins;
 
   ts = TODO_SPEC (insn);
   gcc_assert (!(ts & ~BE_IN_SPEC));
@@ -8060,7 +8060,7 @@ add_to_speculative_block (rtx_insn *insn)
 fprintf (spec_info->dump, ";;\t\tGenerated twin insn : %d/rec%d\n",
  INSN_UID (twin), rec->index);
 
-  twins = alloc_INSN_LIST (twin, twins);
+  twins.safe_push (twin);
 
   /* Add dependences between TWIN and all appropriate
 instructions from REC.  */
@@ -8099,23 +8099,14 @@ add_to_speculative_block (rtx_insn *insn)
 
   /* We couldn't have added the dependencies between INSN and TWINS earlier
  because that would make TWINS appear in the INSN_BACK_DEPS (INSN).  */
-  while (twins)
+  unsigned int i;
+  rtx_insn *twin;
+  FOR_EACH_VEC_ELT_REVERSE (twins, i, twin)
 {
-  rtx_insn *twin;
-  rtx_insn_list *next_node;
-
-  twin = twins->insn ();
-
-  {
-   dep_def _new_dep, *new_dep = &_new_dep;
+  dep_def _new_dep, *new_dep = &_new_dep;
 
-   init_dep (new_dep, insn, twin, REG_DEP_OUTPUT);
-   sd_add_dep (new_dep, false);
-  }
-
-  next_node = twins->next ();
-  free_INSN_LIST_node (twins);
-  twins = next_node;
+  init_dep (new_dep, insn, twin, REG_DEP_OUTPUT);
+  sd_add_dep (new_dep, false);
 }
 
   calc_priorities (priorities_roots);
-- 
2.9.0



[PATCH 1/3] make pattern_regs a vec

2016-07-24 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-07-24  Trevor Saunders  

* store-motion.c (struct st_expr): Make pattern_regs a vector.
(extract_mentioned_regs): Append to a vector instead of
returning a rtx_expr_list.
(st_expr_entry): Adjust.
(store_ops_ok): Likewise.
(store_killed_in_insn): Likewise.
(find_moveable_store): Likewise.
---
 gcc/store-motion.c | 51 +--
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/gcc/store-motion.c b/gcc/store-motion.c
index 6d7d37f..0293d96 100644
--- a/gcc/store-motion.c
+++ b/gcc/store-motion.c
@@ -63,7 +63,7 @@ struct st_expr
   /* Pattern of this mem.  */
   rtx pattern;
   /* List of registers mentioned by the mem.  */
-  rtx pattern_regs;
+  vec pattern_regs;
   /* INSN list of stores that are locally anticipatable.  */
   vec antic_stores;
   /* INSN list of stores that are locally available.  */
@@ -146,7 +146,7 @@ st_expr_entry (rtx x)
 
   ptr->next = store_motion_mems;
   ptr->pattern  = x;
-  ptr->pattern_regs = NULL_RTX;
+  ptr->pattern_regs.create (0);
   ptr->antic_stores.create (0);
   ptr->avail_stores.create (0);
   ptr->reaching_reg = NULL_RTX;
@@ -248,16 +248,13 @@ print_store_motion_mems (FILE * file)
due to set of registers in bitmap REGS_SET.  */
 
 static bool
-store_ops_ok (const_rtx x, int *regs_set)
+store_ops_ok (const vec , int *regs_set)
 {
-  const_rtx reg;
-
-  for (; x; x = XEXP (x, 1))
-{
-  reg = XEXP (x, 0);
-  if (regs_set[REGNO (reg)])
-   return false;
-}
+  unsigned int i;
+  rtx temp;
+  FOR_EACH_VEC_ELT (x, i, temp)
+if (regs_set[REGNO (temp)])
+  return false;
 
   return true;
 }
@@ -265,18 +262,16 @@ store_ops_ok (const_rtx x, int *regs_set)
 /* Returns a list of registers mentioned in X.
FIXME: A regset would be prettier and less expensive.  */
 
-static rtx_expr_list *
-extract_mentioned_regs (rtx x)
+static void
+extract_mentioned_regs (rtx x, vec *mentioned_regs)
 {
-  rtx_expr_list *mentioned_regs = NULL;
   subrtx_var_iterator::array_type array;
   FOR_EACH_SUBRTX_VAR (iter, array, x, NONCONST)
 {
   rtx x = *iter;
   if (REG_P (x))
-   mentioned_regs = alloc_EXPR_LIST (0, x, mentioned_regs);
+   mentioned_regs->safe_push (x);
 }
-  return mentioned_regs;
 }
 
 /* Check to see if the load X is aliased with STORE_PATTERN.
@@ -373,9 +368,10 @@ store_killed_in_pat (const_rtx x, const_rtx pat, int after)
after the insn.  Return true if it does.  */
 
 static bool
-store_killed_in_insn (const_rtx x, const_rtx x_regs, const rtx_insn *insn, int 
after)
+store_killed_in_insn (const_rtx x, const vec _regs,
+ const rtx_insn *insn, int after)
 {
-  const_rtx reg, note, pat;
+  const_rtx note, pat;
 
   if (! NONDEBUG_INSN_P (insn))
 return false;
@@ -389,8 +385,10 @@ store_killed_in_insn (const_rtx x, const_rtx x_regs, const 
rtx_insn *insn, int a
 
   /* But even a const call reads its parameters.  Check whether the
 base of some of registers used in mem is stack pointer.  */
-  for (reg = x_regs; reg; reg = XEXP (reg, 1))
-   if (may_be_sp_based_p (XEXP (reg, 0)))
+  rtx temp;
+  unsigned int i;
+  FOR_EACH_VEC_ELT (x_regs, i, temp)
+   if (may_be_sp_based_p (temp))
  return true;
 
   return false;
@@ -435,8 +433,8 @@ store_killed_in_insn (const_rtx x, const_rtx x_regs, const 
rtx_insn *insn, int a
is killed, return the last insn in that it occurs in FAIL_INSN.  */
 
 static bool
-store_killed_after (const_rtx x, const_rtx x_regs, const rtx_insn *insn,
-   const_basic_block bb,
+store_killed_after (const_rtx x, const vec _regs,
+   const rtx_insn *insn, const_basic_block bb,
int *regs_set_after, rtx *fail_insn)
 {
   rtx_insn *last = BB_END (bb), *act;
@@ -465,8 +463,9 @@ store_killed_after (const_rtx x, const_rtx x_regs, const 
rtx_insn *insn,
within basic block BB. X_REGS is list of registers mentioned in X.
REGS_SET_BEFORE is bitmap of registers set before or in this insn.  */
 static bool
-store_killed_before (const_rtx x, const_rtx x_regs, const rtx_insn *insn,
-const_basic_block bb, int *regs_set_before)
+store_killed_before (const_rtx x, const vec _regs,
+const rtx_insn *insn, const_basic_block bb,
+int *regs_set_before)
 {
   rtx_insn *first = BB_HEAD (bb);
 
@@ -555,8 +554,8 @@ find_moveable_store (rtx_insn *insn, int *regs_set_before, 
int *regs_set_after)
 return;
 
   ptr = st_expr_entry (dest);
-  if (!ptr->pattern_regs)
-ptr->pattern_regs = extract_mentioned_regs (dest);
+  if (ptr->pattern_regs.is_empty ())
+extract_mentioned_regs (dest, >pattern_regs);
 
   /* Do not check for anticipatability if we either found one anticipatable
  store already, or tested for 

[PATCH 0/3] more removal of rtl lists

2016-07-24 Thread tbsaunde+gcc
From: Trevor Saunders 

Hi,

Here's a few more patches getting rid of usage of rtl lists.  In patches 1 and
2 a list is created and then iterated over, which would generally seem to be a
better fit for a vector than a linked list.  The code involved in patch 3
doesn't really use a list at all, it just simplifies an API that used a list
node.

patches bootstrapped on x86_64-linux-gnu, and I checked one target per effected
config/ directory still builds, ok?

Trev

Trevor Saunders (3):
  make pattern_regs a vec
  haifa-sched.c: make twins a auto_vec
  merge adjust_cost and adjust_cost_2 target hooks

 gcc/config/alpha/alpha.c   |  5 ++--
 gcc/config/arm/arm-protos.h|  2 +-
 gcc/config/arm/arm.c   | 40 --
 gcc/config/bfin/bfin.c |  5 ++--
 gcc/config/c6x/c6x.c   |  5 ++--
 gcc/config/epiphany/epiphany.c |  5 ++--
 gcc/config/i386/i386.c |  5 ++--
 gcc/config/ia64/ia64.c | 10 
 gcc/config/m68k/m68k.c |  7 +++---
 gcc/config/microblaze/microblaze.c | 10 +++-
 gcc/config/mips/mips.c |  8 ++
 gcc/config/mn10300/mn10300.c   |  5 ++--
 gcc/config/pa/pa.c |  9 ---
 gcc/config/rs6000/rs6000.c | 16 ++--
 gcc/config/sh/sh.c | 10 
 gcc/config/sparc/sparc.c   | 23 +
 gcc/config/spu/spu.c   |  5 ++--
 gcc/config/tilegx/tilegx.c |  6 ++---
 gcc/config/tilepro/tilepro.c   |  6 ++---
 gcc/config/visium/visium.c | 11 
 gcc/doc/tm.texi| 14 +--
 gcc/haifa-sched.c  | 50 -
 gcc/store-motion.c | 51 +++---
 gcc/target.def | 25 +++
 24 files changed, 155 insertions(+), 178 deletions(-)

-- 
2.9.0



[PATCH 3/6] add ctor to topo_info

2016-07-24 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-07-24  Trevor Saunders  

* tree-ssa-structalias.c (struct topo_info): Add constructor,
and change types of members to auto_vec and auto_sbitmap.
(init_topo_info): Remove.
(topo_info::topo_info): New constructor.
(solve_graph): Adjust.
---
 gcc/tree-ssa-structalias.c | 31 ---
 1 file changed, 8 insertions(+), 23 deletions(-)

diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 5e3c7d0..94d81ed1 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -1536,36 +1536,21 @@ unify_nodes (constraint_graph_t graph, unsigned int to, 
unsigned int from,
 
 struct topo_info
 {
+  topo_info ();
+
   /* sbitmap of visited nodes.  */
-  sbitmap visited;
+  auto_sbitmap visited;
   /* Array that stores the topological order of the graph, *in
  reverse*.  */
-  vec topo_order;
+  auto_vec topo_order;
 };
 
 
 /* Initialize and return a topological info structure.  */
 
-static struct topo_info *
-init_topo_info (void)
-{
-  size_t size = graph->size;
-  struct topo_info *ti = XNEW (struct topo_info);
-  ti->visited = sbitmap_alloc (size);
-  bitmap_clear (ti->visited);
-  ti->topo_order.create (1);
-  return ti;
-}
-
-
-/* Free the topological sort info pointed to by TI.  */
-
-static void
-free_topo_info (struct topo_info *ti)
+topo_info::topo_info () : visited (graph->size), topo_order (1)
 {
-  sbitmap_free (ti->visited);
-  ti->topo_order.release ();
-  free (ti);
+  bitmap_clear (visited);
 }
 
 /* Visit the graph in topological order, and store the order in the
@@ -2679,7 +2664,7 @@ solve_graph (constraint_graph_t graph)
   while (!bitmap_empty_p (changed))
 {
   unsigned int i;
-  struct topo_info *ti = init_topo_info ();
+  topo_info *ti = new topo_info ();
   stats.iterations++;
 
   bitmap_obstack_initialize (_obstack);
@@ -2797,7 +2782,7 @@ solve_graph (constraint_graph_t graph)
}
}
}
-  free_topo_info (ti);
+  delete ti;
   bitmap_obstack_release (_obstack);
 }
 
-- 
2.9.0



[PATCH 2/6] use auto_sbitmap in various places

2016-07-24 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-07-24  Trevor Saunders  

* bt-load.c (compute_out): Use auto_sbitmap class.
(link_btr_uses): Likewise.
* cfganal.c (mark_dfs_back_edges): Likewise.
(post_order_compute): Likewise.
(inverted_post_order_compute): Likewise.
(pre_and_rev_post_order_compute_fn): Likewise.
(single_pred_before_succ_order): Likewise.
* cfgexpand.c (pass_expand::execute): Likewise.
* cfgloop.c (verify_loop_structure): Likewise.
* cfgloopmanip.c (fix_bb_placements): Likewise.
(remove_path): Likewise.
(update_dominators_in_loop): Likewise.
* cfgrtl.c (break_superblocks): Likewise.
* ddg.c (check_sccs): Likewise.
(create_ddg_all_sccs): Likewise.
* df-core.c (df_worklist_dataflow): Likewise.
* dse.c (dse_step3): Likewise.
* except.c (eh_region_outermost): Likewise.
* function.c (thread_prologue_and_epilogue_insns): Likewise.
* gcse.c (prune_expressions): Likewise.
(prune_insertions_deletions): Likewise.
* gimple-ssa-backprop.c (backprop::~backprop): Likewise.
* graph.c (draw_cfg_nodes_no_loops): Likewise.
* ira-lives.c (remove_some_program_points_and_update_live_ranges): 
Likewise.
* lcm.c (compute_earliest): Likewise.
(compute_farthest): Likewise.
* loop-unroll.c (unroll_loop_constant_iterations): Likewise.
(unroll_loop_runtime_iterations): Likewise.
(unroll_loop_stupid): Likewise.
* lower-subreg.c (decompose_multiword_subregs): Likewise.
* lra-lives.c: Likewise.
* lra.c (lra): Likewise.
* modulo-sched.c (schedule_reg_moves): Likewise.
(optimize_sc): Likewise.
(get_sched_window): Likewise.
(sms_schedule_by_order): Likewise.
(check_nodes_order): Likewise.
(order_nodes_of_sccs): Likewise.
(order_nodes_in_scc): Likewise.
* recog.c (split_all_insns): Likewise.
* regcprop.c (pass_cprop_hardreg::execute): Likewise.
* reload1.c (reload): Likewise.
* sched-rgn.c (haifa_find_rgns): Likewise.
(split_edges): Likewise.
(compute_trg_info): Likewise.
* sel-sched.c (init_seqno): Likewise.
* store-motion.c (remove_reachable_equiv_notes): Likewise.
* tree-into-ssa.c (update_ssa): Likewise.
* tree-ssa-live.c (live_worklist): Likewise.
* tree-ssa-loop-im.c (fill_always_executed_in): Likewise.
* tree-ssa-loop-ivcanon.c (try_unroll_loop_completely):
* Likewise.
(try_peel_loop): Likewise.
* tree-ssa-loop-manip.c (tree_transform_and_unroll_loop):
* Likewise.
* tree-ssa-pre.c (compute_antic): Likewise.
* tree-ssa-reassoc.c (undistribute_ops_list): Likewise.
* tree-stdarg.c (reachable_at_most_once): Likewise.
* tree-vect-slp.c (vect_attempt_slp_rearrange_stmts): Likewise.
* var-tracking.c (vt_find_locations): Likewise.
---
 gcc/bt-load.c   |  9 ++
 gcc/cfganal.c   | 19 +++
 gcc/cfgexpand.c |  4 +--
 gcc/cfgloop.c   |  8 ++---
 gcc/cfgloopmanip.c  | 13 ++--
 gcc/cfgrtl.c|  5 +--
 gcc/ddg.c   | 12 +++
 gcc/df-core.c   |  3 +-
 gcc/dse.c   |  3 +-
 gcc/except.c|  5 +--
 gcc/function.c  |  3 +-
 gcc/gcse.c  |  9 ++
 gcc/gimple-ssa-backprop.c   |  5 ++-
 gcc/graph.c |  5 +--
 gcc/ira-lives.c | 11 +++
 gcc/lcm.c   | 16 ++
 gcc/loop-unroll.c   | 16 ++
 gcc/lower-subreg.c  |  5 +--
 gcc/lra-lives.c | 10 ++
 gcc/lra.c   |  4 +--
 gcc/modulo-sched.c  | 78 ++---
 gcc/recog.c |  5 +--
 gcc/regcprop.c  |  4 +--
 gcc/reload1.c   |  4 +--
 gcc/sched-rgn.c | 36 ++---
 gcc/sel-sched.c |  4 +--
 gcc/store-motion.c  |  3 +-
 gcc/tree-into-ssa.c |  3 +-
 gcc/tree-ssa-live.c |  4 +--
 gcc/tree-ssa-loop-im.c  |  4 +--
 gcc/tree-ssa-loop-ivcanon.c | 10 ++
 gcc/tree-ssa-loop-manip.c   |  4 +--
 gcc/tree-ssa-pre.c  |  3 +-
 gcc/tree-ssa-reassoc.c  | 12 ++-
 gcc/tree-stdarg.c   |  4 +--
 gcc/tree-vect-slp.c | 20 +++-
 gcc/var-tracking.c  |  5 ++-
 37 files changed, 99 insertions(+), 269 deletions(-)

diff --git a/gcc/bt-load.c b/gcc/bt-load.c
index aa02f64..5b1bcec 100644
--- a/gcc/bt-load.c
+++ b/gcc/bt-load.c
@@ -626,7 +626,7 @@ compute_out (sbitmap *bb_out, sbitmap *bb_gen, sbitmap 
*bb_kill, int max_uid)
  Iterate until the bb_out sets stop growing.  */
   int i;
   int changed;
-  sbitmap bb_in = sbitmap_alloc 

[PATCH 4/6] remove elim_graph typedef

2016-07-24 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-07-24  Trevor Saunders  

* tree-outof-ssa.c (struct elim_graph): Remove typedef.
(new_elim_graph): Adjust.
(clear_elim_graph): Likewise.
(delete_elim_graph): Likewise.
(elim_graph_size): Likewise.
(elim_graph_add_node): Likewise.
(elim_graph_add_edge): Likewise.
(elim_graph_remove_succ_edge): Likewise.
(eliminate_name): Likewise.
(eliminate_build): Likewise.
(elim_forward): Likewise.
(elim_unvisited_predecessor): Likewise.
(elim_backward): Likewise.
(elim_create): Likewise.
(eliminate_phi): Likewise.
(expand_phi_nodes): Likewise.
---
 gcc/tree-outof-ssa.c | 37 +++--
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/gcc/tree-outof-ssa.c b/gcc/tree-outof-ssa.c
index 4125529..5047788 100644
--- a/gcc/tree-outof-ssa.c
+++ b/gcc/tree-outof-ssa.c
@@ -126,7 +126,8 @@ ssa_is_replaceable_p (gimple *stmt)
rarely more than 6, and in the bootstrap of gcc, the maximum number
of nodes encountered was 12.  */
 
-typedef struct _elim_graph {
+struct elim_graph
+{
   /* Size of the elimination vectors.  */
   int size;
 
@@ -157,7 +158,7 @@ typedef struct _elim_graph {
 
   /* Source locations for any constant copies.  */
   vec copy_locus;
-} *elim_graph;
+};
 
 
 /* For an edge E find out a good source location to associate with
@@ -394,10 +395,10 @@ insert_part_to_rtx_on_edge (edge e, rtx dest, int src, 
source_location locus)
 /* Create an elimination graph with SIZE nodes and associated data
structures.  */
 
-static elim_graph
+static elim_graph *
 new_elim_graph (int size)
 {
-  elim_graph g = (elim_graph) xmalloc (sizeof (struct _elim_graph));
+  elim_graph *g = (elim_graph *) xmalloc (sizeof (struct elim_graph));
 
   g->nodes.create (30);
   g->const_dests.create (20);
@@ -416,7 +417,7 @@ new_elim_graph (int size)
 /* Empty elimination graph G.  */
 
 static inline void
-clear_elim_graph (elim_graph g)
+clear_elim_graph (elim_graph *g)
 {
   g->nodes.truncate (0);
   g->edge_list.truncate (0);
@@ -427,7 +428,7 @@ clear_elim_graph (elim_graph g)
 /* Delete elimination graph G.  */
 
 static inline void
-delete_elim_graph (elim_graph g)
+delete_elim_graph (elim_graph *g)
 {
   sbitmap_free (g->visited);
   g->stack.release ();
@@ -445,7 +446,7 @@ delete_elim_graph (elim_graph g)
 /* Return the number of nodes in graph G.  */
 
 static inline int
-elim_graph_size (elim_graph g)
+elim_graph_size (elim_graph *g)
 {
   return g->nodes.length ();
 }
@@ -454,7 +455,7 @@ elim_graph_size (elim_graph g)
 /* Add NODE to graph G, if it doesn't exist already.  */
 
 static inline void
-elim_graph_add_node (elim_graph g, int node)
+elim_graph_add_node (elim_graph *g, int node)
 {
   int x;
   int t;
@@ -469,7 +470,7 @@ elim_graph_add_node (elim_graph g, int node)
 /* Add the edge PRED->SUCC to graph G.  */
 
 static inline void
-elim_graph_add_edge (elim_graph g, int pred, int succ, source_location locus)
+elim_graph_add_edge (elim_graph *g, int pred, int succ, source_location locus)
 {
   g->edge_list.safe_push (pred);
   g->edge_list.safe_push (succ);
@@ -481,7 +482,7 @@ elim_graph_add_edge (elim_graph g, int pred, int succ, 
source_location locus)
return the successor node.  -1 is returned if there is no such edge.  */
 
 static inline int
-elim_graph_remove_succ_edge (elim_graph g, int node, source_location *locus)
+elim_graph_remove_succ_edge (elim_graph *g, int node, source_location *locus)
 {
   int y;
   unsigned x;
@@ -543,7 +544,7 @@ do {
\
 /* Add T to elimination graph G.  */
 
 static inline void
-eliminate_name (elim_graph g, int T)
+eliminate_name (elim_graph *g, int T)
 {
   elim_graph_add_node (g, T);
 }
@@ -570,7 +571,7 @@ queue_phi_copy_p (var_map map, tree t)
G->e.  */
 
 static void
-eliminate_build (elim_graph g)
+eliminate_build (elim_graph *g)
 {
   tree Ti;
   int p0, pi;
@@ -619,7 +620,7 @@ eliminate_build (elim_graph g)
 /* Push successors of T onto the elimination stack for G.  */
 
 static void
-elim_forward (elim_graph g, int T)
+elim_forward (elim_graph *g, int T)
 {
   int S;
   source_location locus;
@@ -637,7 +638,7 @@ elim_forward (elim_graph g, int T)
 /* Return 1 if there unvisited predecessors of T in graph G.  */
 
 static int
-elim_unvisited_predecessor (elim_graph g, int T)
+elim_unvisited_predecessor (elim_graph *g, int T)
 {
   int P;
   source_location locus;
@@ -653,7 +654,7 @@ elim_unvisited_predecessor (elim_graph g, int T)
 /* Process predecessors first, and insert a copy.  */
 
 static void
-elim_backward (elim_graph g, int T)
+elim_backward (elim_graph *g, int T)
 {
   int P;
   source_location locus;
@@ -688,7 +689,7 @@ get_temp_reg (tree name)
region, and create a temporary to break the cycle if one is found.  

[PATCH 6/6] add [cd]tors to scc_info

2016-07-24 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-07-24  Trevor Saunders  

* tree-ssa-structalias.c (struct scc_info): Change types of
members to auto_sbitmap and auto_vec.
(scc_info::scc_info): New constructor.
(scc_info::~scc_info): New destructor.
(init_scc_info): Remove.
(free_scc_info): Remove.
(find_indirect_cycles): Adjust.
(perform_var_substitution): Likewise.
(free_var_substitution_info): Likewise.
---
 gcc/tree-ssa-structalias.c | 57 ++
 1 file changed, 22 insertions(+), 35 deletions(-)

diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 94d81ed1..a669065 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -1379,12 +1379,15 @@ static bitmap changed;
 
 struct scc_info
 {
-  sbitmap visited;
-  sbitmap deleted;
+  scc_info (size_t size);
+  ~scc_info ();
+
+  auto_sbitmap visited;
+  auto_sbitmap deleted;
   unsigned int *dfs;
   unsigned int *node_mapping;
   int current_index;
-  vec scc_stack;
+  auto_vec scc_stack;
 };
 
 
@@ -1809,38 +1812,24 @@ do_complex_constraint (constraint_graph_t graph, 
constraint_t c, bitmap delta,
 
 /* Initialize and return a new SCC info structure.  */
 
-static struct scc_info *
-init_scc_info (size_t size)
+scc_info::scc_info (size_t size) :
+  visited (size), deleted (size), current_index (0), scc_stack (1)
 {
-  struct scc_info *si = XNEW (struct scc_info);
-  size_t i;
-
-  si->current_index = 0;
-  si->visited = sbitmap_alloc (size);
-  bitmap_clear (si->visited);
-  si->deleted = sbitmap_alloc (size);
-  bitmap_clear (si->deleted);
-  si->node_mapping = XNEWVEC (unsigned int, size);
-  si->dfs = XCNEWVEC (unsigned int, size);
-
-  for (i = 0; i < size; i++)
-si->node_mapping[i] = i;
+  bitmap_clear (visited);
+  bitmap_clear (deleted);
+  node_mapping = XNEWVEC (unsigned int, size);
+  dfs = XCNEWVEC (unsigned int, size);
 
-  si->scc_stack.create (1);
-  return si;
+  for (size_t i = 0; i < size; i++)
+node_mapping[i] = i;
 }
 
 /* Free an SCC info structure pointed to by SI */
 
-static void
-free_scc_info (struct scc_info *si)
+scc_info::~scc_info ()
 {
-  sbitmap_free (si->visited);
-  sbitmap_free (si->deleted);
-  free (si->node_mapping);
-  free (si->dfs);
-  si->scc_stack.release ();
-  free (si);
+  free (node_mapping);
+  free (dfs);
 }
 
 
@@ -1856,13 +1845,11 @@ find_indirect_cycles (constraint_graph_t graph)
 {
   unsigned int i;
   unsigned int size = graph->size;
-  struct scc_info *si = init_scc_info (size);
+  scc_info si (size);
 
   for (i = 0; i < MIN (LAST_REF_NODE, size); i ++ )
-if (!bitmap_bit_p (si->visited, i) && find (i) == i)
-  scc_visit (graph, si, i);
-
-  free_scc_info (si);
+if (!bitmap_bit_p (si.visited, i) && find (i) == i)
+  scc_visit (graph, , i);
 }
 
 /* Compute a topological ordering for GRAPH, and store the result in the
@@ -2276,7 +2263,7 @@ perform_var_substitution (constraint_graph_t graph)
 {
   unsigned int i;
   unsigned int size = graph->size;
-  struct scc_info *si = init_scc_info (size);
+  scc_info *si = new scc_info (size);
 
   bitmap_obstack_initialize (_obstack);
   pointer_equiv_class_table = new hash_table (511);
@@ -2407,7 +2394,7 @@ perform_var_substitution (constraint_graph_t graph)
 static void
 free_var_substitution_info (struct scc_info *si)
 {
-  free_scc_info (si);
+  delete si;
   free (graph->pointer_label);
   free (graph->loc_label);
   free (graph->pointed_by);
-- 
2.9.0



[PATCH 5/6] add a constructor to elim_graph

2016-07-24 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-07-24  Trevor Saunders  

* tree-outof-ssa.c (struct elim_graph): Change type of members
to auto_vec and auto_sbitmap.
(elim_graph::elim_graph): New constructor.
(delete_elim_graph): Remove.
(expand_phi_nodes): Adjust.
---
 gcc/tree-outof-ssa.c | 64 +---
 1 file changed, 16 insertions(+), 48 deletions(-)

diff --git a/gcc/tree-outof-ssa.c b/gcc/tree-outof-ssa.c
index 5047788..be57ce4 100644
--- a/gcc/tree-outof-ssa.c
+++ b/gcc/tree-outof-ssa.c
@@ -128,23 +128,25 @@ ssa_is_replaceable_p (gimple *stmt)
 
 struct elim_graph
 {
+  elim_graph (var_map map);
+
   /* Size of the elimination vectors.  */
   int size;
 
   /* List of nodes in the elimination graph.  */
-  vec nodes;
+  auto_vec nodes;
 
   /*  The predecessor and successor edge list.  */
-  vec edge_list;
+  auto_vec edge_list;
 
   /* Source locus on each edge */
-  vec edge_locus;
+  auto_vec edge_locus;
 
   /* Visited vector.  */
-  sbitmap visited;
+  auto_sbitmap visited;
 
   /* Stack for visited nodes.  */
-  vec stack;
+  auto_vec stack;
 
   /* The variable partition map.  */
   var_map map;
@@ -153,11 +155,11 @@ struct elim_graph
   edge e;
 
   /* List of constant copies to emit.  These are pushed on in pairs.  */
-  vec const_dests;
-  vec const_copies;
+  auto_vec const_dests;
+  auto_vec const_copies;
 
   /* Source locations for any constant copies.  */
-  vec copy_locus;
+  auto_vec copy_locus;
 };
 
 
@@ -392,25 +394,12 @@ insert_part_to_rtx_on_edge (edge e, rtx dest, int src, 
source_location locus)
 }
 
 
-/* Create an elimination graph with SIZE nodes and associated data
-   structures.  */
+/* Create an elimination graph for map.  */
 
-static elim_graph *
-new_elim_graph (int size)
+elim_graph::elim_graph (var_map map) :
+  nodes (30), edge_list (20), edge_locus (10), visited (map->num_partitions),
+  stack (30), map (map), const_dests (20), const_copies (20), copy_locus (10)
 {
-  elim_graph *g = (elim_graph *) xmalloc (sizeof (struct elim_graph));
-
-  g->nodes.create (30);
-  g->const_dests.create (20);
-  g->const_copies.create (20);
-  g->copy_locus.create (10);
-  g->edge_list.create (20);
-  g->edge_locus.create (10);
-  g->stack.create (30);
-
-  g->visited = sbitmap_alloc (size);
-
-  return g;
 }
 
 
@@ -425,24 +414,6 @@ clear_elim_graph (elim_graph *g)
 }
 
 
-/* Delete elimination graph G.  */
-
-static inline void
-delete_elim_graph (elim_graph *g)
-{
-  sbitmap_free (g->visited);
-  g->stack.release ();
-  g->edge_list.release ();
-  g->const_copies.release ();
-  g->const_dests.release ();
-  g->nodes.release ();
-  g->copy_locus.release ();
-  g->edge_locus.release ();
-
-  free (g);
-}
-
-
 /* Return the number of nodes in graph G.  */
 
 static inline int
@@ -925,8 +896,7 @@ void
 expand_phi_nodes (struct ssaexpand *sa)
 {
   basic_block bb;
-  elim_graph *g = new_elim_graph (sa->map->num_partitions);
-  g->map = sa->map;
+  elim_graph g (sa->map);
 
   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb,
  EXIT_BLOCK_PTR_FOR_FN (cfun), next_bb)
@@ -935,7 +905,7 @@ expand_phi_nodes (struct ssaexpand *sa)
edge e;
edge_iterator ei;
FOR_EACH_EDGE (e, ei, bb->preds)
- eliminate_phi (e, g);
+ eliminate_phi (e, );
set_phi_nodes (bb, NULL);
/* We can't redirect EH edges in RTL land, so we need to do this
   here.  Redirection happens only when splitting is necessary,
@@ -961,8 +931,6 @@ expand_phi_nodes (struct ssaexpand *sa)
  ei_next ();
  }
   }
-
-  delete_elim_graph (g);
 }
 
 
-- 
2.9.0



[PATCH 0/6] add and use an auto_sbitmap class

2016-07-24 Thread tbsaunde+gcc
From: Trevor Saunders 

Hi,

This series adds a auto_sbitmap class that manages the lifetime of a sbitmap.
Then it replaces most manual management with uses of auto_sbitmap.

patches individually bootstrapped + regtested on x86_linux-gnu, ok?

Trev


Trevor Saunders (6):
  add auto_sbitmap class
  use auto_sbitmap in various places
  add ctor to topo_info
  remove elim_graph typedef
  add a constructor to elim_graph
  add [cd]tors to scc_info

 gcc/bt-load.c   |  9 ++---
 gcc/cfganal.c   | 19 +++--
 gcc/cfgexpand.c |  4 +-
 gcc/cfgloop.c   |  8 +---
 gcc/cfgloopmanip.c  | 13 ++-
 gcc/cfgrtl.c|  5 +--
 gcc/ddg.c   | 12 ++
 gcc/df-core.c   |  3 +-
 gcc/dse.c   |  3 +-
 gcc/except.c|  5 +--
 gcc/function.c  |  3 +-
 gcc/gcse.c  |  9 +
 gcc/gimple-ssa-backprop.c   |  5 +--
 gcc/graph.c |  5 +--
 gcc/ira-lives.c | 11 ++
 gcc/lcm.c   | 16 +---
 gcc/loop-unroll.c   | 16 ++--
 gcc/lower-subreg.c  |  5 +--
 gcc/lra-lives.c | 10 ++---
 gcc/lra.c   |  4 +-
 gcc/modulo-sched.c  | 78 -
 gcc/recog.c |  5 +--
 gcc/regcprop.c  |  4 +-
 gcc/reload1.c   |  4 +-
 gcc/sbitmap.h   | 21 ++
 gcc/sched-rgn.c | 36 +-
 gcc/sel-sched.c |  4 +-
 gcc/store-motion.c  |  3 +-
 gcc/tree-into-ssa.c |  3 +-
 gcc/tree-outof-ssa.c| 93 +++--
 gcc/tree-ssa-live.c |  4 +-
 gcc/tree-ssa-loop-im.c  |  4 +-
 gcc/tree-ssa-loop-ivcanon.c | 10 +
 gcc/tree-ssa-loop-manip.c   |  4 +-
 gcc/tree-ssa-pre.c  |  3 +-
 gcc/tree-ssa-reassoc.c  | 12 ++
 gcc/tree-ssa-structalias.c  | 88 +++---
 gcc/tree-stdarg.c   |  4 +-
 gcc/tree-vect-slp.c | 20 +++---
 gcc/var-tracking.c  |  5 +--
 40 files changed, 181 insertions(+), 389 deletions(-)

-- 
2.9.0



[PATCH 1/6] add auto_sbitmap class

2016-07-24 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-07-24  Trevor Saunders  

* sbitmap.h (auto_sbitmap): New class.
---
 gcc/sbitmap.h | 21 +
 1 file changed, 21 insertions(+)

diff --git a/gcc/sbitmap.h b/gcc/sbitmap.h
index c208171..d4a2918 100644
--- a/gcc/sbitmap.h
+++ b/gcc/sbitmap.h
@@ -256,4 +256,25 @@ extern int bitmap_last_set_bit (const_sbitmap);
 
 extern void debug_bitmap (const_sbitmap);
 extern sbitmap sbitmap_realloc (sbitmap, unsigned int);
+
+/* a class that ties the lifetime of a sbitmap to its scope.  */
+class auto_sbitmap
+{
+public:
+  explicit auto_sbitmap (unsigned int size) :
+m_bitmap (sbitmap_alloc (size)) {}
+  ~auto_sbitmap () { sbitmap_free (m_bitmap); }
+
+  /* Allow calling sbitmap functions on our bitmap.  */
+  operator sbitmap () { return m_bitmap; }
+
+private:
+  /* Prevent making a copy that refers to our sbitmap.  */
+  auto_sbitmap (const auto_sbitmap &);
+  auto_sbitmap  = (const auto_sbitmap &);
+
+  /* The bitmap we are managing.  */
+  sbitmap m_bitmap;
+};
+
 #endif /* ! GCC_SBITMAP_H */
-- 
2.9.0



[PATCH 6/9] ree.c: use auto_vec in ext_state

2016-06-29 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-06-29  Trevor Saunders  

* ree.c (struct ext_state): Make type of members auto_vec.
(find_and_remove_re): Adjust.
---
 gcc/ree.c | 19 ++-
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/gcc/ree.c b/gcc/ree.c
index 4627b4f..3245ac5 100644
--- a/gcc/ree.c
+++ b/gcc/ree.c
@@ -544,10 +544,10 @@ struct ext_state
   /* In order to avoid constant alloc/free, we keep these
  4 vectors live through the entire find_and_remove_re and just
  truncate them each time.  */
-  vec defs_list;
-  vec copies_list;
-  vec modified_list;
-  vec work_list;
+  auto_vec defs_list;
+  auto_vec copies_list;
+  auto_vec modified_list;
+  auto_vec work_list;
 
   /* For instructions that have been successfully modified, this is
  the original mode from which the insn is extending and
@@ -1147,7 +1147,6 @@ find_and_remove_re (void)
   vec reinsn_list;
   auto_vec reinsn_del_list;
   auto_vec reinsn_copy_list;
-  ext_state state;
 
   /* Construct DU chain to get all reaching definitions of each
  extension instruction.  */
@@ -1159,10 +1158,8 @@ find_and_remove_re (void)
 
   max_insn_uid = get_max_uid ();
   reinsn_list = find_removable_extensions ();
-  state.defs_list.create (0);
-  state.copies_list.create (0);
-  state.modified_list.create (0);
-  state.work_list.create (0);
+
+  ext_state state;
   if (reinsn_list.is_empty ())
 state.modified = NULL;
   else
@@ -1238,10 +1235,6 @@ find_and_remove_re (void)
 delete_insn (curr_insn);
 
   reinsn_list.release ();
-  state.defs_list.release ();
-  state.copies_list.release ();
-  state.modified_list.release ();
-  state.work_list.release ();
   XDELETEVEC (state.modified);
 
   if (dump_file && num_re_opportunities > 0)
-- 
2.7.4



[PATCH 9/9] remove unnecessary calls to vec::release

2016-06-29 Thread tbsaunde+gcc
From: Trevor Saunders 

There's no point in calling release () on an auto_vec just before it goes
out of scope.

gcc/ChangeLog:

2016-06-29  Trevor Saunders  

* tree-data-ref.c (find_data_references_in_stmt): Remove
unnecessary call to vec::release.
(graphite_find_data_references_in_stmt): Likewise.
* tree-ssa-alias.c (nonoverlapping_component_refs_of_decl_p): Likewise.
* tree-vect-stmts.c (vectorizable_condition): Likewise.
---
 gcc/tree-data-ref.c   |  3 +--
 gcc/tree-ssa-alias.c  | 21 +++--
 gcc/tree-vect-stmts.c |  3 ---
 3 files changed, 8 insertions(+), 19 deletions(-)

diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
index 1a7a2ea..acdaa2f 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -3999,7 +3999,7 @@ find_data_references_in_stmt (struct loop *nest, gimple 
*stmt,
   gcc_assert (dr != NULL);
   datarefs->safe_push (dr);
 }
-  references.release ();
+
   return ret;
 }
 
@@ -4029,7 +4029,6 @@ graphite_find_data_references_in_stmt (loop_p nest, 
loop_p loop, gimple *stmt,
   datarefs->safe_push (dr);
 }
 
-  references.release ();
   return ret;
 }
 
diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
index b663ddf..0ffa8c2 100644
--- a/gcc/tree-ssa-alias.c
+++ b/gcc/tree-ssa-alias.c
@@ -865,7 +865,7 @@ nonoverlapping_component_refs_of_decl_p (tree ref1, tree 
ref2)
   if (TREE_CODE (ref1) == MEM_REF)
 {
   if (!integer_zerop (TREE_OPERAND (ref1, 1)))
-   goto may_overlap;
+   return false;
   ref1 = TREE_OPERAND (TREE_OPERAND (ref1, 0), 0);
 }
 
@@ -878,7 +878,7 @@ nonoverlapping_component_refs_of_decl_p (tree ref1, tree 
ref2)
   if (TREE_CODE (ref2) == MEM_REF)
 {
   if (!integer_zerop (TREE_OPERAND (ref2, 1)))
-   goto may_overlap;
+   return false;
   ref2 = TREE_OPERAND (TREE_OPERAND (ref2, 0), 0);
 }
 
@@ -898,7 +898,7 @@ nonoverlapping_component_refs_of_decl_p (tree ref1, tree 
ref2)
   do
{
  if (component_refs1.is_empty ())
-   goto may_overlap;
+   return false;
  ref1 = component_refs1.pop ();
}
   while (!RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (ref1, 0;
@@ -906,7 +906,7 @@ nonoverlapping_component_refs_of_decl_p (tree ref1, tree 
ref2)
   do
{
  if (component_refs2.is_empty ())
-goto may_overlap;
+return false;
  ref2 = component_refs2.pop ();
}
   while (!RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (ref2, 0;
@@ -914,7 +914,7 @@ nonoverlapping_component_refs_of_decl_p (tree ref1, tree 
ref2)
   /* Beware of BIT_FIELD_REF.  */
   if (TREE_CODE (ref1) != COMPONENT_REF
  || TREE_CODE (ref2) != COMPONENT_REF)
-   goto may_overlap;
+   return false;
 
   tree field1 = TREE_OPERAND (ref1, 1);
   tree field2 = TREE_OPERAND (ref2, 1);
@@ -927,21 +927,14 @@ nonoverlapping_component_refs_of_decl_p (tree ref1, tree 
ref2)
 
   /* We cannot disambiguate fields in a union or qualified union.  */
   if (type1 != type2 || TREE_CODE (type1) != RECORD_TYPE)
-goto may_overlap;
+return false;
 
   /* Different fields of the same record type cannot overlap.
 ??? Bitfields can overlap at RTL level so punt on them.  */
   if (field1 != field2)
-   {
- component_refs1.release ();
- component_refs2.release ();
- return !(DECL_BIT_FIELD (field1) && DECL_BIT_FIELD (field2));
-   }
+   return !(DECL_BIT_FIELD (field1) && DECL_BIT_FIELD (field2));
 }
 
-may_overlap:
-  component_refs1.release ();
-  component_refs2.release ();
   return false;
 }
 
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 3281860..0238504 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -7614,9 +7614,6 @@ vectorizable_condition (gimple *stmt, 
gimple_stmt_iterator *gsi,
  if (!masked)
vec_oprnds1 = vec_defs.pop ();
  vec_oprnds0 = vec_defs.pop ();
-
-  ops.release ();
-  vec_defs.release ();
 }
   else
 {
-- 
2.7.4



[PATCH 8/9] use auto_vec for more local variables

2016-06-29 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/c/ChangeLog:

2016-06-29  Trevor Saunders  

* c-parser.c (c_parser_generic_selection): Make type of variable
auto_vec.
(c_parser_omp_declare_simd): Likewise.

gcc/ChangeLog:

2016-06-29  Trevor Saunders  

* cfgexpand.c (expand_used_vars): Make the type of a local variable 
auto_vec.
* genmatch.c (lower_for): Likewise.
* haifa-sched.c (haifa_sched_init): Likewise.
(add_to_speculative_block): Likewise.
(create_check_block_twin): Likewise.
* predict.c (handle_missing_profiles): Likewise.
* tree-data-ref.c (loop_nest_has_data_refs): Likewise.
* tree-diagnostic.c (maybe_unwind_expanded_macro_loc): Likewise.
* tree-ssa-loop-niter.c (discover_iteration_bound_by_body_walk): 
Likewise.
(maybe_lower_iteration_bound): Likewise.
* tree-ssa-sccvn.c (DFS): Likewise.
* tree-stdarg.c (reachable_at_most_once): Likewise.
* tree-vect-stmts.c (vectorizable_conversion): Likewise.
(vectorizable_store): Likewise.
---
 gcc/c/c-parser.c  | 22 ++
 gcc/cfgexpand.c   |  3 +--
 gcc/genmatch.c| 12 
 gcc/haifa-sched.c | 15 ---
 gcc/predict.c |  4 +---
 gcc/tree-data-ref.c   |  5 +
 gcc/tree-diagnostic.c |  4 +---
 gcc/tree-ssa-loop-niter.c |  6 ++
 gcc/tree-ssa-sccvn.c  | 16 
 gcc/tree-stdarg.c |  3 +--
 gcc/tree-vect-stmts.c |  8 ++--
 11 files changed, 27 insertions(+), 71 deletions(-)

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 7f491f1..18dc618 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -7243,7 +7243,6 @@ struct c_generic_association
 static struct c_expr
 c_parser_generic_selection (c_parser *parser)
 {
-  vec associations = vNULL;
   struct c_expr selector, error_expr;
   tree selector_type;
   struct c_generic_association matched_assoc;
@@ -7300,6 +7299,7 @@ c_parser_generic_selection (c_parser *parser)
   return error_expr;
 }
 
+  auto_vec associations;
   while (1)
 {
   struct c_generic_association assoc, *iter;
@@ -7320,13 +7320,13 @@ c_parser_generic_selection (c_parser *parser)
  if (type_name == NULL)
{
  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
- goto error_exit;
+ return error_expr;
}
  assoc.type = groktypename (type_name, NULL, NULL);
  if (assoc.type == error_mark_node)
{
  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
- goto error_exit;
+ return error_expr;
}
 
  if (TREE_CODE (assoc.type) == FUNCTION_TYPE)
@@ -7345,14 +7345,14 @@ c_parser_generic_selection (c_parser *parser)
   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
{
  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
- goto error_exit;
+ return error_expr;
}
 
   assoc.expression = c_parser_expr_no_commas (parser, NULL);
   if (assoc.expression.value == error_mark_node)
{
  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
- goto error_exit;
+ return error_expr;
}
 
   for (ix = 0; associations.iterate (ix, ); ++ix)
@@ -7408,8 +7408,6 @@ c_parser_generic_selection (c_parser *parser)
   c_parser_consume_token (parser);
 }
 
-  associations.release ();
-
   if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
 {
   c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
@@ -7425,10 +7423,6 @@ c_parser_generic_selection (c_parser *parser)
 }
 
   return matched_assoc.expression;
-
- error_exit:
-  associations.release ();
-  return error_expr;
 }
 
 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
@@ -16362,14 +16356,13 @@ check_clauses:
 static void
 c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context)
 {
-  vec clauses = vNULL;
+  auto_vec clauses;
   while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
 {
   c_token *token = c_parser_peek_token (parser);
   if (token->type == CPP_EOF)
{
  c_parser_skip_to_pragma_eol (parser);
- clauses.release ();
  return;
}
   clauses.safe_push (*token);
@@ -16391,7 +16384,6 @@ c_parser_omp_declare_simd (c_parser *parser, enum 
pragma_context context)
  "%<#pragma omp declare simd%> must be followed by "
  "function declaration or definition or another "
  "%<#pragma omp declare simd%>");
- clauses.release ();
  return;
}
   c_parser_consume_pragma (parser);
@@ -16401,7 +16393,6 @@ c_parser_omp_declare_simd (c_parser *parser, enum 
pragma_context context)
   

[PATCH 4/9] ipa.c: remove static_{ctors,dtors} globals

2016-06-29 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-06-29  Trevor Saunders  

* ipa.c (record_cdtor_fn): Adjust.
(build_cdtor_fns): Likewise.
(ipa_cdtor_merge): Make static_ctors and static_dtors local
variables.
---
 gcc/ipa.c | 37 +
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/gcc/ipa.c b/gcc/ipa.c
index 6722d3b..2609e32 100644
--- a/gcc/ipa.c
+++ b/gcc/ipa.c
@@ -989,11 +989,6 @@ cgraph_build_static_cdtor (char which, tree body, int 
priority)
   cgraph_build_static_cdtor_1 (which, body, priority, false);
 }
 
-/* A vector of FUNCTION_DECLs declared as static constructors.  */
-static vec static_ctors;
-/* A vector of FUNCTION_DECLs declared as static destructors.  */
-static vec static_dtors;
-
 /* When target does not have ctors and dtors, we call all constructor
and destructor by special initialization/destruction function
recognized by collect2.
@@ -1002,12 +997,12 @@ static vec static_dtors;
destructors and turn them into normal functions.  */
 
 static void
-record_cdtor_fn (struct cgraph_node *node)
+record_cdtor_fn (struct cgraph_node *node, vec *ctors, vec *dtors)
 {
   if (DECL_STATIC_CONSTRUCTOR (node->decl))
-static_ctors.safe_push (node->decl);
+ctors->safe_push (node->decl);
   if (DECL_STATIC_DESTRUCTOR (node->decl))
-static_dtors.safe_push (node->decl);
+dtors->safe_push (node->decl);
   node = cgraph_node::get (node->decl);
   DECL_DISREGARD_INLINE_LIMITS (node->decl) = 1;
 }
@@ -1018,7 +1013,7 @@ record_cdtor_fn (struct cgraph_node *node)
they are destructors.  */
 
 static void
-build_cdtor (bool ctor_p, vec cdtors)
+build_cdtor (bool ctor_p, const vec )
 {
   size_t i,j;
   size_t len = cdtors.length ();
@@ -1135,20 +1130,20 @@ compare_dtor (const void *p1, const void *p2)
functions have magic names which are detected by collect2.  */
 
 static void
-build_cdtor_fns (void)
+build_cdtor_fns (vec *ctors, vec *dtors)
 {
-  if (!static_ctors.is_empty ())
+  if (!ctors->is_empty ())
 {
   gcc_assert (!targetm.have_ctors_dtors || in_lto_p);
-  static_ctors.qsort (compare_ctor);
-  build_cdtor (/*ctor_p=*/true, static_ctors);
+  ctors->qsort (compare_ctor);
+  build_cdtor (/*ctor_p=*/true, *ctors);
 }
 
-  if (!static_dtors.is_empty ())
+  if (!dtors->is_empty ())
 {
   gcc_assert (!targetm.have_ctors_dtors || in_lto_p);
-  static_dtors.qsort (compare_dtor);
-  build_cdtor (/*ctor_p=*/false, static_dtors);
+  dtors->qsort (compare_dtor);
+  build_cdtor (/*ctor_p=*/false, *dtors);
 }
 }
 
@@ -1161,14 +1156,16 @@ build_cdtor_fns (void)
 static unsigned int
 ipa_cdtor_merge (void)
 {
+  /* A vector of FUNCTION_DECLs declared as static constructors.  */
+  auto_vec ctors;
+  /* A vector of FUNCTION_DECLs declared as static destructors.  */
+  auto_vec dtors;
   struct cgraph_node *node;
   FOR_EACH_DEFINED_FUNCTION (node)
 if (DECL_STATIC_CONSTRUCTOR (node->decl)
|| DECL_STATIC_DESTRUCTOR (node->decl))
-   record_cdtor_fn (node);
-  build_cdtor_fns ();
-  static_ctors.release ();
-  static_dtors.release ();
+   record_cdtor_fn (node, , );
+  build_cdtor_fns (, );
   return 0;
 }
 
-- 
2.7.4



[PATCH 3/9] genextract.c: add [cd]tors to accum_extract

2016-06-29 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-06-29  Trevor Saunders  

* genextract.c (struct accum_extract): Add constructor and make
members auto_vec.
(gen_insn): Adjust.
---
 gcc/genextract.c | 23 +++
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/gcc/genextract.c b/gcc/genextract.c
index d591781..e6d5337 100644
--- a/gcc/genextract.c
+++ b/gcc/genextract.c
@@ -69,10 +69,12 @@ static struct code_ptr *peepholes;
 
 struct accum_extract
 {
-  vec oplocs;
-  vec duplocs;
-  vec dupnums;
-  vec pathstr;
+  accum_extract () : oplocs (10), duplocs (10), dupnums (10), pathstr (20) {}
+
+  auto_vec oplocs;
+  auto_vec duplocs;
+  auto_vec dupnums;
+  auto_vec pathstr;
 };
 
 /* Forward declarations.  */
@@ -87,11 +89,6 @@ gen_insn (md_rtx_info *info)
   struct code_ptr *link;
   struct accum_extract acc;
 
-  acc.oplocs.create (10);
-  acc.duplocs.create (10);
-  acc.dupnums.create (10);
-  acc.pathstr.create (20);
-
   /* Walk the insn's pattern, remembering at all times the path
  down to the walking point.  */
 
@@ -142,7 +139,7 @@ gen_insn (md_rtx_info *info)
   /* This extraction is the same as ours.  Just link us in.  */
   link->next = p->insns;
   p->insns = link;
-  goto done;
+  return;
 }
 
   /* Otherwise, make a new extraction method.  We stash the arrays
@@ -166,12 +163,6 @@ gen_insn (md_rtx_info *info)
   memcpy (p->oplocs, acc.oplocs.address (), op_count * sizeof (locstr));
   memcpy (p->duplocs, acc.duplocs.address (), dup_count * sizeof (locstr));
   memcpy (p->dupnums, acc.dupnums.address (), dup_count * sizeof (int));
-
- done:
-  acc.oplocs.release ();
-  acc.duplocs.release ();
-  acc.dupnums.release ();
-  acc.pathstr.release ();
 }
 
 /* Helper subroutine of walk_rtx: given a vec, an index, and a
-- 
2.7.4



[PATCH 7/9] tree-ssa-sccvn.c: use auto_vec for sccvn_dom_walker::cond_stack

2016-06-29 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-06-29  Trevor Saunders  

* tree-ssa-sccvn.c (sccvn_dom_walker::~sccvn_dom_walker): remove.
(sccvn_dom_walker): make cond_stack an auto_vec.
---
 gcc/tree-ssa-sccvn.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index 0cbd2cd..95306c5 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -,8 +,7 @@ class sccvn_dom_walker : public dom_walker
 {
 public:
   sccvn_dom_walker ()
-: dom_walker (CDI_DOMINATORS, true), fail (false), cond_stack (vNULL) {}
-  ~sccvn_dom_walker ();
+: dom_walker (CDI_DOMINATORS, true), fail (false), cond_stack (0) {}
 
   virtual edge before_dom_children (basic_block);
   virtual void after_dom_children (basic_block);
@@ -4456,15 +4455,10 @@ public:
 enum tree_code code, tree lhs, tree rhs, bool value);
 
   bool fail;
-  vec > >
+  auto_vec > >
 cond_stack;
 };
 
-sccvn_dom_walker::~sccvn_dom_walker ()
-{
-  cond_stack.release ();
-}
-
 /* Record a temporary condition for the BB and its dominated blocks.  */
 
 void
-- 
2.7.4



[PATCH 2/9] c-decl.c: add [cd]tors to c_struct_parse_info

2016-06-29 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/c/ChangeLog:

2016-06-29  Trevor Saunders  

* c-decl.c (struct c_struct_parse_info): Add constructor and
change member types from vec to auto_vec.
(start_struct): Adjust.
(finish_struct): Likewise.
---
 gcc/c/c-decl.c | 16 +---
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 8b966fe..c173796 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -574,15 +574,15 @@ struct c_struct_parse_info
 {
   /* If warn_cxx_compat, a list of types defined within this
  struct.  */
-  vec struct_types;
+  auto_vec struct_types;
   /* If warn_cxx_compat, a list of field names which have bindings,
  and which are defined in this struct, but which are not defined
  in any enclosing struct.  This is used to clear the in_struct
  field of the c_bindings structure.  */
-  vec fields;
+  auto_vec fields;
   /* If warn_cxx_compat, a list of typedef names used when defining
  fields in this struct.  */
-  vec typedefs_seen;
+  auto_vec typedefs_seen;
 };
 
 /* Information for the struct or union currently being parsed, or
@@ -7443,10 +7443,7 @@ start_struct (location_t loc, enum tree_code code, tree 
name,
 TYPE_PACKED (v) = flag_pack_struct;
 
   *enclosing_struct_parse_info = struct_parse_info;
-  struct_parse_info = XNEW (struct c_struct_parse_info);
-  struct_parse_info->struct_types.create (0);
-  struct_parse_info->fields.create (0);
-  struct_parse_info->typedefs_seen.create (0);
+  struct_parse_info = new c_struct_parse_info ();
 
   /* FIXME: This will issue a warning for a use of a type defined
  within a statement expr used within sizeof, et. al.  This is not
@@ -8088,10 +8085,7 @@ finish_struct (location_t loc, tree t, tree fieldlist, 
tree attributes,
   if (warn_cxx_compat)
 warn_cxx_compat_finish_struct (fieldlist, TREE_CODE (t), loc);
 
-  struct_parse_info->struct_types.release ();
-  struct_parse_info->fields.release ();
-  struct_parse_info->typedefs_seen.release ();
-  XDELETE (struct_parse_info);
+  delete struct_parse_info;
 
   struct_parse_info = enclosing_struct_parse_info;
 
-- 
2.7.4



[PATCH 5/9] cfgexpand.c: use auto_vec in stack_vars_data

2016-06-29 Thread tbsaunde+gcc
From: Trevor Saunders 

gcc/ChangeLog:

2016-06-29  Trevor Saunders  

* cfgexpand.c (struct stack_vars_data): Make type of fields
auto_vec.
(expand_used_vars): Adjust.
---
 gcc/cfgexpand.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index e4ddb3a..9750586 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -1030,10 +1030,10 @@ struct stack_vars_data
   /* Vector of offset pairs, always end of some padding followed
  by start of the padding that needs Address Sanitizer protection.
  The vector is in reversed, highest offset pairs come first.  */
-  vec asan_vec;
+  auto_vec asan_vec;
 
   /* Vector of partition representative decls in between the paddings.  */
-  vec asan_decl_vec;
+  auto_vec asan_decl_vec;
 
   /* Base pseudo register for Address Sanitizer protected automatic vars.  */
   rtx asan_base;
@@ -2179,8 +2179,6 @@ expand_used_vars (void)
 {
   struct stack_vars_data data;
 
-  data.asan_vec = vNULL;
-  data.asan_decl_vec = vNULL;
   data.asan_base = NULL_RTX;
   data.asan_alignb = 0;
 
@@ -2239,9 +2237,6 @@ expand_used_vars (void)
}
 
   expand_stack_vars (NULL, );
-
-  data.asan_vec.release ();
-  data.asan_decl_vec.release ();
 }
 
   fini_vars_expansion ();
-- 
2.7.4



  1   2   3   4   >