From: tbsaunde+gcc@tbsaunde.org
To: gcc-patches@gcc.gnu.org
Cc: palves@redhat.com
Subject: [PATCH 2/2] use unique_ptr some
Date: Mon, 31 Jul 2017 23:46:00 -0000 [thread overview]
Message-ID: <20170731234607.21952-3-tbsaunde+gcc@tbsaunde.org> (raw)
In-Reply-To: <20170731234607.21952-1-tbsaunde+gcc@tbsaunde.org>
From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
gcc/ChangeLog:
2017-07-31 Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
* 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<rtx> *visited = NULL;
+ gtl::unique_ptr<hash_set<rtx> > 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<rtx>;
+ visited.reset (new hash_set<rtx>);
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;
}
\f
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<uint32_t[]> 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<basic_block> 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<basic_block[]> entry_pred (new basic_block[num_entry_edges]);
+ gtl::unique_ptr<int[]> entry_flag (new int[num_entry_edges]);
+ gtl::unique_ptr<profile_probability[]> 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<basic_block[]> exit_succ;
+ gtl::unique_ptr<int[]> exit_flag;
+ gtl::unique_ptr<profile_probability[]> 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 int[num_exit_edges]);
+ exit_prob.reset (new profile_probability[num_exit_edges]);
i = 0;
for (ei = ei_start (exit_bb->succs); (e = ei_safe_edge (ei)) != NULL;)
{
@@ -7319,12 +7322,7 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
}
}
else
- {
- num_exit_edges = 0;
- exit_succ = NULL;
- exit_flag = NULL;
- exit_prob = NULL;
- }
+ num_exit_edges = 0;
/* Switch context to the child function to initialize DEST_FN's CFG. */
gcc_assert (dest_cfun->cfg == NULL);
@@ -7534,16 +7532,6 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
FOR_EACH_VEC_ELT (dom_bbs, i, abb)
set_immediate_dominator (CDI_DOMINATORS, abb, bb);
dom_bbs.release ();
-
- if (exit_bb)
- {
- free (exit_prob);
- free (exit_flag);
- free (exit_succ);
- }
- free (entry_prob);
- free (entry_flag);
- free (entry_pred);
bbs.release ();
return bb;
--
2.11.0
next prev parent reply other threads:[~2017-07-31 23:46 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-31 23:46 [PATCH 0/2] add unique_ptr class tbsaunde+gcc
2017-07-31 23:46 ` [PATCH 1/2] add unique_ptr header tbsaunde+gcc
2017-08-01 14:40 ` David Malcolm
2017-08-02 3:09 ` Trevor Saunders
2017-08-04 19:55 ` Jonathan Wakely
2017-08-05 5:39 ` Trevor Saunders
2017-10-11 18:52 ` David Malcolm
2017-10-12 14:08 ` Trevor Saunders
2017-10-13 3:05 ` [PATCH] Add gnu::unique_ptr David Malcolm
2017-10-13 9:36 ` Richard Biener
2017-10-13 12:08 ` Pedro Alves
2017-10-14 0:35 ` [PATCH] Implement unique_xmalloc_ptr<T[]> and add more selftests David Malcolm
2017-10-16 10:53 ` Pedro Alves
2017-10-16 21:04 ` [committed] Add gnu::unique_ptr David Malcolm
2017-10-19 17:27 ` Gerald Pfeifer
2017-10-19 17:41 ` David Malcolm
2017-10-22 11:40 ` Gerald Pfeifer
2017-08-02 8:14 ` [PATCH 1/2] add unique_ptr header Richard Biener
2017-07-31 23:46 ` tbsaunde+gcc [this message]
2017-08-01 0:51 ` [PATCH 0/2] add unique_ptr class David Malcolm
2017-08-04 18:52 ` Jonathan Wakely
2017-08-05 5:36 ` Trevor Saunders
2017-08-07 13:01 ` Jonathan Wakely
2017-08-05 19:05 ` Pedro Alves
2017-08-11 21:30 ` Jonathan Wakely
2017-09-03 1:24 ` Trevor Saunders
2017-09-04 9:31 ` Richard Biener
2017-09-04 10:05 ` Pedro Alves
2017-09-05 16:52 ` Manuel López-Ibáñez
2017-09-05 17:40 ` Pedro Alves
2017-09-06 12:35 ` replace libiberty with gnulib (was: Re: [PATCH 0/2] add unique_ptr class) Manuel López-Ibáñez
2017-08-04 22:43 ` [PATCH 0/2] add unique_ptr class Martin Sebor
2017-08-05 5:32 ` Trevor Saunders
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170731234607.21952-3-tbsaunde+gcc@tbsaunde.org \
--to=tbsaunde+gcc@tbsaunde.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=palves@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).