Make gimple_build main workers more flexible
authorRichard Biener <rguenther@suse.de>
Thu, 12 May 2022 06:24:12 +0000 (08:24 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 13 May 2022 06:18:33 +0000 (08:18 +0200)
The following makes the main gimple_build API take a
gimple_stmt_iterator, whether to insert before or after and
an iterator update argument to make it more convenient to use
in certain situations (see the tree-vect-generic.cc hunks for
an example).  It also makes the case we insert into the IL
somewhat distinct from inserting into a standalone sequence in
that it simplifies built expressions the same way as inserting
and calling fold_stmt (..., follow_all_ssa_edges) would.  When
inserting into a standalone sequence we restrict simplification
to defs within the currently building sequence.

The patch only amends the tree_code gimple_build API, I will
followup with converting the rest as well.  The patch got larger
than intended because the template forwarders now use gsi_last
which introduces a dependency on gimple-iterator.h requiring
mass #include re-org across the tree.  There are two frontend
specific files including gimple-fold.h just for some padding
clearing stuff - I've removed the include and instead moved
the declarations to fold-const.h (but not the implementations).
Otherwise I'd have to include half of the middle-end headers in
those files which I didn't much like.

2022-05-12  Richard Biener  <rguenther@suse.de>

gcc/cp/
* constexpr.cc: Remove gimple-fold.h include.

gcc/c-family/
* c-omp.cc: Remove gimple-fold.h include.

gcc/analyzer/
* supergraph.cc: Re-order gimple-fold.h include.

gcc/
* gimple-fold.cc (gimple_build): Adjust for new
main API.
* gimple-fold.h (gimple_build): New main APIs with
iterator, insert direction and iterator update.
(gimple_build): New forwarder template.
(clear_padding_type_may_have_padding_p): Remove.
(clear_type_padding_in_mask): Likewise.
(arith_overflowed_p): Likewise.
* fold-const.h (clear_padding_type_may_have_padding_p): Declare.
(clear_type_padding_in_mask): Likewise.
(arith_overflowed_p): Likewise.
* tree-vect-generic.cc (gimplify_build3): Use main gimple_build API.
(gimplify_build2): Likewise.
(gimplify_build1): Likewise.
* ubsan.cc (ubsan_expand_ptr_ifn): Likewise, avoid extra
compare stmt.
* gengtype.cc (open_base_files): Re-order includes.
* builtins.cc: Re-order gimple-fold.h include.
* calls.cc: Likewise.
* cgraphbuild.cc: Likewise.
* cgraphunit.cc: Likewise.
* config/rs6000/rs6000-builtin.cc: Likewise.
* config/rs6000/rs6000-call.cc: Likewise.
* config/rs6000/rs6000.cc: Likewise.
* config/s390/s390.cc: Likewise.
* expr.cc: Likewise.
* fold-const.cc: Likewise.
* function-tests.cc: Likewise.
* gimple-match-head.cc: Likewise.
* gimple-range-fold.cc: Likewise.
* gimple-ssa-evrp-analyze.cc: Likewise.
* gimple-ssa-evrp.cc: Likewise.
* gimple-ssa-sprintf.cc: Likewise.
* gimple-ssa-warn-access.cc: Likewise.
* gimplify.cc: Likewise.
* graphite-isl-ast-to-gimple.cc: Likewise.
* ipa-cp.cc: Likewise.
* ipa-devirt.cc: Likewise.
* ipa-prop.cc: Likewise.
* omp-low.cc: Likewise.
* pointer-query.cc: Likewise.
* range-op.cc: Likewise.
* tree-cfg.cc: Likewise.
* tree-if-conv.cc: Likewise.
* tree-inline.cc: Likewise.
* tree-object-size.cc: Likewise.
* tree-ssa-ccp.cc: Likewise.
* tree-ssa-dom.cc: Likewise.
* tree-ssa-forwprop.cc: Likewise.
* tree-ssa-ifcombine.cc: Likewise.
* tree-ssa-loop-ivcanon.cc: Likewise.
* tree-ssa-math-opts.cc: Likewise.
* tree-ssa-pre.cc: Likewise.
* tree-ssa-propagate.cc: Likewise.
* tree-ssa-reassoc.cc: Likewise.
* tree-ssa-sccvn.cc: Likewise.
* tree-ssa-strlen.cc: Likewise.
* tree-ssa.cc: Likewise.
* value-pointer-equiv.cc: Likewise.
* vr-values.cc: Likewise.

gcc/testsuite/
* gcc.dg/plugin/diagnostic_group_plugin.c: Reorder or remove
gimple-fold.h include.
* gcc.dg/plugin/diagnostic_plugin_show_trees.c:
Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_inlining.c:
Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_metadata.c:
Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_paths.c:
Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c:
Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_string_literals.c: Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c:
Likewise.
* gcc.dg/plugin/finish_unit_plugin.c: Likewise.
* gcc.dg/plugin/ggcplug.c: Likewise.
* gcc.dg/plugin/must_tail_call_plugin.c: Likewise.
* gcc.dg/plugin/one_time_plugin.c: Likewise.
* gcc.dg/plugin/selfassign.c: Likewise.
* gcc.dg/plugin/start_unit_plugin.c: Likewise.
* g++.dg/plugin/selfassign.c: Likewise.

67 files changed:
gcc/analyzer/supergraph.cc
gcc/builtins.cc
gcc/c-family/c-omp.cc
gcc/calls.cc
gcc/cgraphbuild.cc
gcc/cgraphunit.cc
gcc/config/rs6000/rs6000-builtin.cc
gcc/config/rs6000/rs6000-call.cc
gcc/config/rs6000/rs6000.cc
gcc/config/s390/s390.cc
gcc/cp/constexpr.cc
gcc/expr.cc
gcc/fold-const.cc
gcc/fold-const.h
gcc/function-tests.cc
gcc/gengtype.cc
gcc/gimple-fold.cc
gcc/gimple-fold.h
gcc/gimple-match-head.cc
gcc/gimple-range-fold.cc
gcc/gimple-ssa-evrp-analyze.cc
gcc/gimple-ssa-evrp.cc
gcc/gimple-ssa-sprintf.cc
gcc/gimple-ssa-warn-access.cc
gcc/gimplify.cc
gcc/graphite-isl-ast-to-gimple.cc
gcc/ipa-cp.cc
gcc/ipa-devirt.cc
gcc/ipa-prop.cc
gcc/omp-low.cc
gcc/pointer-query.cc
gcc/range-op.cc
gcc/testsuite/g++.dg/plugin/selfassign.c
gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.c
gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c
gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.c
gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_metadata.c
gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c
gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c
gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c
gcc/testsuite/gcc.dg/plugin/finish_unit_plugin.c
gcc/testsuite/gcc.dg/plugin/ggcplug.c
gcc/testsuite/gcc.dg/plugin/must_tail_call_plugin.c
gcc/testsuite/gcc.dg/plugin/one_time_plugin.c
gcc/testsuite/gcc.dg/plugin/selfassign.c
gcc/testsuite/gcc.dg/plugin/start_unit_plugin.c
gcc/tree-cfg.cc
gcc/tree-if-conv.cc
gcc/tree-inline.cc
gcc/tree-object-size.cc
gcc/tree-ssa-ccp.cc
gcc/tree-ssa-dom.cc
gcc/tree-ssa-forwprop.cc
gcc/tree-ssa-ifcombine.cc
gcc/tree-ssa-loop-ivcanon.cc
gcc/tree-ssa-math-opts.cc
gcc/tree-ssa-pre.cc
gcc/tree-ssa-propagate.cc
gcc/tree-ssa-reassoc.cc
gcc/tree-ssa-sccvn.cc
gcc/tree-ssa-strlen.cc
gcc/tree-ssa.cc
gcc/tree-vect-generic.cc
gcc/ubsan.cc
gcc/value-pointer-equiv.cc
gcc/vr-values.cc

index 466f924..f023c53 100644 (file)
@@ -29,13 +29,13 @@ along with GCC; see the file COPYING3.  If not see
 #include "ggc.h"
 #include "basic-block.h"
 #include "function.h"
+#include "gimple.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
 #include "timevar.h"
-#include "gimple.h"
-#include "gimple-iterator.h"
 #include "gimple-pretty-print.h"
 #include "tree-pretty-print.h"
 #include "graphviz.h"
index 5b085e3..5fc89ad 100644 (file)
@@ -67,13 +67,13 @@ along with GCC; see the file COPYING3.  If not see
 #include "asan.h"
 #include "internal-fn.h"
 #include "case-cfn-macros.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "intl.h"
 #include "file-prefix-map.h" /* remap_macro_filename()  */
 #include "gomp-constants.h"
 #include "omp-general.h"
 #include "tree-dfa.h"
-#include "gimple-iterator.h"
 #include "gimple-ssa.h"
 #include "tree-ssa-live.h"
 #include "tree-outof-ssa.h"
index 987ba7d..01ef4ee 100644 (file)
@@ -36,7 +36,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimplify.h"
 #include "langhooks.h"
 #include "bitmap.h"
-#include "gimple-fold.h"
 
 
 /* Complete a #pragma oacc wait construct.  LOC is the location of
index 4d0bc45..bbaf69c 100644 (file)
@@ -55,6 +55,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "hash-traits.h"
 #include "attribs.h"
 #include "builtins.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "attr-fnspec.h"
 #include "value-query.h"
index 138484c..fdd17aa 100644 (file)
@@ -26,8 +26,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple.h"
 #include "tree-pass.h"
 #include "cgraph.h"
-#include "gimple-fold.h"
 #include "gimple-iterator.h"
+#include "gimple-fold.h"
 #include "gimple-walk.h"
 #include "ipa-utils.h"
 #include "except.h"
index bc3dc75..e77bf97 100644 (file)
@@ -179,9 +179,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "stor-layout.h"
 #include "output.h"
 #include "cfgcleanup.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "gimplify.h"
-#include "gimple-iterator.h"
 #include "gimplify-me.h"
 #include "tree-cfg.h"
 #include "tree-into-ssa.h"
index e925ba9..b60dde9 100644 (file)
@@ -45,8 +45,8 @@
 #include "expr.h"
 #include "langhooks.h"
 #include "gimplify.h"
-#include "gimple-fold.h"
 #include "gimple-iterator.h"
+#include "gimple-fold.h"
 #include "ssa.h"
 #include "tree-ssa-propagate.h"
 #include "builtins.h"
index f06c692..6011fe8 100644 (file)
@@ -55,8 +55,8 @@
 #include "common/common-target.h"
 #include "langhooks.h"
 #include "gimplify.h"
-#include "gimple-fold.h"
 #include "gimple-iterator.h"
+#include "gimple-fold.h"
 #include "ssa.h"
 #include "tree-ssa-propagate.h"
 #include "builtins.h"
index 5cb8a53..d4defc8 100644 (file)
@@ -58,8 +58,8 @@
 #include "reload.h"
 #include "sched-int.h"
 #include "gimplify.h"
-#include "gimple-fold.h"
 #include "gimple-iterator.h"
+#include "gimple-fold.h"
 #include "gimple-walk.h"
 #include "ssa.h"
 #include "tree-vectorizer.h"
index 7c3bd6c..45bbb6c 100644 (file)
@@ -70,6 +70,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "debug.h"
 #include "langhooks.h"
 #include "internal-fn.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimplify.h"
index e560d84..433fa76 100644 (file)
@@ -31,7 +31,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "builtins.h"
 #include "tree-inline.h"
 #include "ubsan.h"
-#include "gimple-fold.h"
 #include "timevar.h"
 #include "fold-const-call.h"
 #include "stor-layout.h"
index 5f7142b..1806091 100644 (file)
@@ -60,6 +60,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-address.h"
 #include "builtins.h"
 #include "ccmp.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "rtx-vector-builder.h"
 #include "tree-pretty-print.h"
index a57ad07..7bf1231 100644 (file)
@@ -70,6 +70,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-dfa.h"
 #include "builtins.h"
 #include "generic-match.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-into-ssa.h"
 #include "md5.h"
index a4ff554..fe78a4d 100644 (file)
@@ -245,6 +245,11 @@ extern tree fold_build_pointer_plus_hwi_loc (location_t loc, tree ptr, HOST_WIDE
 #define fold_build_pointer_plus_hwi(p,o) \
        fold_build_pointer_plus_hwi_loc (UNKNOWN_LOCATION, p, o)
 
+/* In gimple-fold.cc.  */
+extern void clear_type_padding_in_mask (tree, unsigned char *);
+extern bool clear_padding_type_may_have_padding_p (tree);
+extern bool arith_overflowed_p (enum tree_code, const_tree, const_tree,
+                               const_tree);
 
 /* Class used to compare gimple operands.  */
 
index 7d77615..1f983e8 100644 (file)
@@ -47,6 +47,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
+#include "gimple.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "gimple-expr.h"
 #include "toplev.h"
@@ -67,7 +69,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "internal-fn.h"
 #include "gimple-expr.h"
 #include "is-a.h"
-#include "gimple.h"
 #include "tree-pass.h"
 #include "context.h"
 #include "hash-map.h"
index e11da9e..1967625 100644 (file)
@@ -1703,9 +1703,9 @@ open_base_files (void)
       "alias.h", "insn-config.h", "flags.h", "expmed.h", "dojump.h",
       "explow.h", "calls.h", "memmodel.h", "emit-rtl.h", "varasm.h",
       "stmt.h", "expr.h", "alloc-pool.h", "cselib.h", "insn-addr.h",
-      "optabs.h", "libfuncs.h", "debug.h", "internal-fn.h", "gimple-fold.h",
-      "value-range.h",
-      "tree-eh.h", "gimple-iterator.h", "gimple-ssa.h", "tree-cfg.h",
+      "optabs.h", "libfuncs.h", "debug.h", "internal-fn.h",
+      "gimple-iterator.h", "gimple-fold.h", "value-range.h",
+      "tree-eh.h", "gimple-ssa.h", "tree-cfg.h",
       "tree-vrp.h", "tree-phinodes.h", "ssa-iterators.h", "stringpool.h",
       "tree-ssanames.h", "tree-ssa-loop.h", "tree-ssa-loop-ivopts.h",
       "tree-ssa-loop-manip.h", "tree-ssa-loop-niter.h", "tree-into-ssa.h",
index 7baec11..e086b03 100644 (file)
@@ -37,9 +37,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "expr.h"
 #include "stor-layout.h"
 #include "dumpfile.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "gimplify.h"
-#include "gimple-iterator.h"
 #include "tree-into-ssa.h"
 #include "tree-dfa.h"
 #include "tree-object-size.h"
@@ -8669,14 +8669,23 @@ gimple_build_valueize (tree op)
 
 /* Build the expression CODE OP0 of type TYPE with location LOC,
    simplifying it first if possible.  Returns the built
-   expression value and appends statements possibly defining it
-   to SEQ.  */
+   expression value and inserts statements possibly defining it
+   before GSI if BEFORE is true or after GSI if false and advance
+   the iterator accordingly.
+   If gsi refers to a basic block simplifying is allowed to look
+   at all SSA defs while when it does not it is restricted to
+   SSA defs that are not associated with a basic block yet,
+   indicating they belong to the currently building sequence.  */
 
 tree
-gimple_build (gimple_seq *seq, location_t loc,
-             enum tree_code code, tree type, tree op0)
+gimple_build (gimple_stmt_iterator *gsi,
+             bool before, gsi_iterator_update update,
+             location_t loc, enum tree_code code, tree type, tree op0)
 {
-  tree res = gimple_simplify (code, type, op0, seq, gimple_build_valueize);
+  gimple_seq seq = NULL;
+  tree res
+    = gimple_simplify (code, type, op0, &seq,
+                      gsi->bb ? follow_all_ssa_edges : gimple_build_valueize);
   if (!res)
     {
       res = create_tmp_reg_or_ssa_name (type);
@@ -8688,7 +8697,21 @@ gimple_build (gimple_seq *seq, location_t loc,
       else
        stmt = gimple_build_assign (res, code, op0);
       gimple_set_location (stmt, loc);
-      gimple_seq_add_stmt_without_update (seq, stmt);
+      gimple_seq_add_stmt_without_update (&seq, stmt);
+    }
+  if (before)
+    {
+      if (gsi->bb)
+       gsi_insert_seq_before (gsi, seq, update);
+      else
+       gsi_insert_seq_before_without_update (gsi, seq, update);
+    }
+  else
+    {
+      if (gsi->bb)
+       gsi_insert_seq_after (gsi, seq, update);
+      else
+       gsi_insert_seq_after_without_update (gsi, seq, update);
     }
   return res;
 }
@@ -8699,16 +8722,35 @@ gimple_build (gimple_seq *seq, location_t loc,
    to SEQ.  */
 
 tree
-gimple_build (gimple_seq *seq, location_t loc,
-             enum tree_code code, tree type, tree op0, tree op1)
+gimple_build (gimple_stmt_iterator *gsi,
+             bool before, gsi_iterator_update update,
+             location_t loc, enum tree_code code, tree type,
+             tree op0, tree op1)
 {
-  tree res = gimple_simplify (code, type, op0, op1, seq, gimple_build_valueize);
+  gimple_seq seq = NULL;
+  tree res
+    = gimple_simplify (code, type, op0, op1, &seq,
+                      gsi->bb ? follow_all_ssa_edges : gimple_build_valueize);
   if (!res)
     {
       res = create_tmp_reg_or_ssa_name (type);
       gimple *stmt = gimple_build_assign (res, code, op0, op1);
       gimple_set_location (stmt, loc);
-      gimple_seq_add_stmt_without_update (seq, stmt);
+      gimple_seq_add_stmt_without_update (&seq, stmt);
+    }
+  if (before)
+    {
+      if (gsi->bb)
+       gsi_insert_seq_before (gsi, seq, update);
+      else
+       gsi_insert_seq_before_without_update (gsi, seq, update);
+    }
+  else
+    {
+      if (gsi->bb)
+       gsi_insert_seq_after (gsi, seq, update);
+      else
+       gsi_insert_seq_after_without_update (gsi, seq, update);
     }
   return res;
 }
@@ -8719,11 +8761,16 @@ gimple_build (gimple_seq *seq, location_t loc,
    to SEQ.  */
 
 tree
-gimple_build (gimple_seq *seq, location_t loc,
-             enum tree_code code, tree type, tree op0, tree op1, tree op2)
+gimple_build (gimple_stmt_iterator *gsi,
+             bool before, gsi_iterator_update update,
+             location_t loc, enum tree_code code, tree type,
+             tree op0, tree op1, tree op2)
 {
-  tree res = gimple_simplify (code, type, op0, op1, op2,
-                             seq, gimple_build_valueize);
+
+  gimple_seq seq = NULL;
+  tree res
+    = gimple_simplify (code, type, op0, op1, op2, &seq,
+                      gsi->bb ? follow_all_ssa_edges : gimple_build_valueize);
   if (!res)
     {
       res = create_tmp_reg_or_ssa_name (type);
@@ -8734,7 +8781,21 @@ gimple_build (gimple_seq *seq, location_t loc,
       else
        stmt = gimple_build_assign (res, code, op0, op1, op2);
       gimple_set_location (stmt, loc);
-      gimple_seq_add_stmt_without_update (seq, stmt);
+      gimple_seq_add_stmt_without_update (&seq, stmt);
+    }
+  if (before)
+    {
+      if (gsi->bb)
+       gsi_insert_seq_before (gsi, seq, update);
+      else
+       gsi_insert_seq_before_without_update (gsi, seq, update);
+    }
+  else
+    {
+      if (gsi->bb)
+       gsi_insert_seq_after (gsi, seq, update);
+      else
+       gsi_insert_seq_after_without_update (gsi, seq, update);
     }
   return res;
 }
index 850f917..520fde8 100644 (file)
@@ -38,12 +38,8 @@ extern tree maybe_fold_and_comparisons (tree, enum tree_code, tree, tree,
 extern tree maybe_fold_or_comparisons (tree, enum tree_code, tree, tree,
                                       enum tree_code, tree, tree,
                                       basic_block = nullptr);
-extern bool clear_padding_type_may_have_padding_p (tree);
-extern void clear_type_padding_in_mask (tree, unsigned char *);
 extern bool optimize_atomic_compare_exchange_p (gimple *);
 extern void fold_builtin_atomic_compare_exchange (gimple_stmt_iterator *);
-extern bool arith_overflowed_p (enum tree_code, const_tree, const_tree,
-                               const_tree);
 extern tree no_follow_ssa_edges (tree);
 extern tree follow_single_use_edges (tree);
 extern tree follow_all_ssa_edges (tree);
@@ -71,19 +67,35 @@ extern tree tree_vec_extract (gimple_stmt_iterator *, tree, tree, tree, tree);
 /* gimple_build, functionally matching fold_buildN, outputs stmts
    int the provided sequence, matching and simplifying them on-the-fly.
    Supposed to replace force_gimple_operand (fold_buildN (...), ...).  */
-extern tree gimple_build (gimple_seq *, location_t,
-                         enum tree_code, tree, tree);
-extern tree gimple_build (gimple_seq *, location_t,
-                         enum tree_code, tree, tree, tree);
-extern tree gimple_build (gimple_seq *, location_t,
-                         enum tree_code, tree, tree, tree, tree);
+extern tree gimple_build (gimple_stmt_iterator *, bool,
+                         enum gsi_iterator_update,
+                         location_t, enum tree_code, tree, tree);
+extern tree gimple_build (gimple_stmt_iterator *, bool,
+                         enum gsi_iterator_update,
+                         location_t, enum tree_code, tree, tree, tree);
+extern tree gimple_build (gimple_stmt_iterator *, bool,
+                         enum gsi_iterator_update,
+                         location_t, enum tree_code, tree, tree, tree, tree);
+template<class ...Args>
+inline tree
+gimple_build (gimple_seq *seq, location_t loc,
+             enum tree_code code, tree type, Args ...ops)
+{
+  static_assert (sizeof...(ops) > 0 && sizeof...(ops) <= 3,
+                "Number of operands must be from one to three");
+  gimple_stmt_iterator gsi = gsi_last (*seq);
+  return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
+                      loc, code, type, ops...);
+}
 template<class ...Args>
 inline tree
 gimple_build (gimple_seq *seq, enum tree_code code, tree type, Args ...ops)
 {
   static_assert (sizeof...(ops) > 0 && sizeof...(ops) <= 3,
                 "Number of operands must be from one to three");
-  return gimple_build (seq, UNKNOWN_LOCATION, code, type, ops...);
+  gimple_stmt_iterator gsi = gsi_last (*seq);
+  return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
+                      UNKNOWN_LOCATION, code, type, ops...);
 }
 
 extern tree gimple_build (gimple_seq *, location_t, combined_fn, tree);
index 1c74d38..4c80d77 100644 (file)
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "fold-const.h"
 #include "fold-const-call.h"
 #include "stor-layout.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "calls.h"
 #include "tree-dfa.h"
index 3169e29..08d791a 100644 (file)
@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "ssa.h"
 #include "gimple-pretty-print.h"
 #include "optabs-tree.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "wide-int.h"
 #include "fold-const.h"
index fec6e87..16e5a75 100644 (file)
@@ -27,9 +27,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "ssa.h"
 #include "gimple-pretty-print.h"
 #include "cfganal.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
-#include "gimple-iterator.h"
 #include "tree-cfg.h"
 #include "tree-ssa-loop-manip.h"
 #include "tree-ssa-loop.h"
index 2baaed6..92dbdd5 100644 (file)
@@ -27,9 +27,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "ssa.h"
 #include "gimple-pretty-print.h"
 #include "cfganal.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
-#include "gimple-iterator.h"
 #include "tree-cfg.h"
 #include "tree-ssa-loop-manip.h"
 #include "tree-ssa-loop.h"
index 9a84fff..961c1b7 100644 (file)
@@ -53,11 +53,11 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple.h"
 #include "tree-pass.h"
 #include "ssa.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "gimple-pretty-print.h"
 #include "diagnostic-core.h"
 #include "fold-const.h"
-#include "gimple-iterator.h"
 #include "tree-ssa.h"
 #include "tree-object-size.h"
 #include "tree-cfg.h"
index 39aa818..c420424 100644 (file)
@@ -36,8 +36,8 @@
 #include "gimple-ssa-warn-restrict.h"
 #include "diagnostic-core.h"
 #include "fold-const.h"
-#include "gimple-fold.h"
 #include "gimple-iterator.h"
+#include "gimple-fold.h"
 #include "langhooks.h"
 #include "memmodel.h"
 #include "target.h"
index 13413d0..2f6d995 100644 (file)
@@ -42,10 +42,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "varasm.h"
 #include "stmt.h"
 #include "expr.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimplify.h"
-#include "gimple-iterator.h"
 #include "stor-layout.h"
 #include "print-tree.h"
 #include "tree-iterator.h"
index ea1129f..45ed770 100644 (file)
@@ -32,8 +32,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple.h"
 #include "ssa.h"
 #include "fold-const.h"
-#include "gimple-fold.h"
 #include "gimple-iterator.h"
+#include "gimple-fold.h"
 #include "gimplify.h"
 #include "gimplify-me.h"
 #include "tree-eh.h"
index 11f4a32..152fe72 100644 (file)
@@ -113,6 +113,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cgraph.h"
 #include "diagnostic.h"
 #include "fold-const.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "symbol-summary.h"
 #include "tree-vrp.h"
index 6cba208..9f1442d 100644 (file)
@@ -120,6 +120,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "print-tree.h"
 #include "calls.h"
 #include "ipa-utils.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "symbol-summary.h"
 #include "tree-vrp.h"
index 80e67e9..c6c745f 100644 (file)
@@ -31,13 +31,13 @@ along with GCC; see the file COPYING3.  If not see
 #include "cgraph.h"
 #include "diagnostic.h"
 #include "fold-const.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "calls.h"
 #include "stor-layout.h"
 #include "print-tree.h"
 #include "gimplify.h"
-#include "gimple-iterator.h"
 #include "gimplify-me.h"
 #include "gimple-walk.h"
 #include "symbol-summary.h"
index e7818a9..8aebaee 100644 (file)
@@ -37,9 +37,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "fold-const.h"
 #include "stor-layout.h"
 #include "internal-fn.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "gimplify.h"
-#include "gimple-iterator.h"
 #include "gimplify-me.h"
 #include "gimple-walk.h"
 #include "tree-iterator.h"
index d93657f..646606e 100644 (file)
@@ -33,6 +33,7 @@
 #include "langhooks.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "gimple-ssa.h"
 #include "intl.h"
index 47c6dff..eaa0230 100644 (file)
@@ -38,9 +38,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "stor-layout.h"
 #include "calls.h"
 #include "cfganal.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
-#include "gimple-iterator.h"
 #include "gimple-walk.h"
 #include "tree-cfg.h"
 #include "wide-int.h"
index 2c60c18..fd78f57 100644 (file)
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
+#include "gimple.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
-#include "gimple.h"
-#include "gimple-iterator.h"
 #include "tree.h"
 #include "tree-pass.h"
 #include "intl.h"
index 67ca701..3396b38 100644 (file)
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
+#include "gimple.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
-#include "gimple.h"
-#include "gimple-iterator.h"
 #include "tree.h"
 #include "tree-pass.h"
 #include "intl.h"
index ac72503..d81fa57 100644 (file)
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
+#include "gimple.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
-#include "gimple.h"
-#include "gimple-iterator.h"
 #include "tree.h"
 #include "tree-pass.h"
 #include "intl.h"
index d2bfca0..3627f7a 100644 (file)
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
+#include "gimple.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
-#include "gimple.h"
-#include "gimple-iterator.h"
 #include "tree.h"
 #include "tree-pass.h"
 #include "intl.h"
index a610891..4b13afc 100644 (file)
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
+#include "gimple.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
-#include "gimple.h"
-#include "gimple-iterator.h"
 #include "tree.h"
 #include "tree-pass.h"
 #include "intl.h"
index 5c2da02..8d97fe8 100644 (file)
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
+#include "gimple.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
-#include "gimple.h"
-#include "gimple-iterator.h"
 #include "tree.h"
 #include "tree-pass.h"
 #include "intl.h"
index 482dbda..baa6b62 100644 (file)
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
+#include "gimple.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
-#include "gimple.h"
-#include "gimple-iterator.h"
 #include "tree.h"
 #include "tree-pass.h"
 #include "intl.h"
index aa73dca..0269f72 100644 (file)
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
+#include "gimple.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
-#include "gimple.h"
-#include "gimple-iterator.h"
 #include "tree.h"
 #include "tree-pass.h"
 #include "intl.h"
index 4a89d84..f546863 100644 (file)
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
+#include "gimple.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
-#include "gimple.h"
-#include "gimple-iterator.h"
 #include "tree.h"
 #include "tree-pass.h"
 #include "intl.h"
index 1b4f7cc..05e1881 100644 (file)
@@ -15,7 +15,6 @@
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
-#include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
index c186d11..a75eed0 100644 (file)
@@ -14,7 +14,6 @@
 #include "ggc.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
-#include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
index 5294f28..0c040e5 100644 (file)
@@ -17,7 +17,6 @@
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
-#include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
index bd1c0f0..84f2d31 100644 (file)
@@ -12,7 +12,6 @@
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
-#include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
index 2adb644..13b3eca 100644 (file)
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
+#include "gimple.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
-#include "gimple.h"
-#include "gimple-iterator.h"
 #include "tree.h"
 #include "tree-pass.h"
 #include "intl.h"
index 61e9494..7b4f40e 100644 (file)
@@ -20,7 +20,6 @@
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
-#include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimple-expr.h"
 #include "is-a.h"
index e321d92..19ba09f 100644 (file)
@@ -37,9 +37,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "stor-layout.h"
 #include "print-tree.h"
 #include "cfganal.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
-#include "gimple-iterator.h"
 #include "gimplify-me.h"
 #include "gimple-walk.h"
 #include "tree-cfg.h"
index 57cc385..4531ca5 100644 (file)
@@ -96,9 +96,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "alias.h"
 #include "fold-const.h"
 #include "stor-layout.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "gimplify.h"
-#include "gimple-iterator.h"
 #include "gimplify-me.h"
 #include "tree-cfg.h"
 #include "tree-into-ssa.h"
index 29bb758..043e1d5 100644 (file)
@@ -41,10 +41,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfganal.h"
 #include "tree-iterator.h"
 #include "intl.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimplify.h"
-#include "gimple-iterator.h"
 #include "gimplify-me.h"
 #include "gimple-walk.h"
 #include "tree-cfg.h"
index fc062b9..5ca87ae 100644 (file)
@@ -29,8 +29,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-pretty-print.h"
 #include "fold-const.h"
 #include "tree-object-size.h"
-#include "gimple-fold.h"
 #include "gimple-iterator.h"
+#include "gimple-fold.h"
 #include "tree-cfg.h"
 #include "tree-dfa.h"
 #include "stringpool.h"
index 9164efe..262a247 100644 (file)
@@ -129,10 +129,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "ssa.h"
 #include "gimple-pretty-print.h"
 #include "fold-const.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimplify.h"
-#include "gimple-iterator.h"
 #include "tree-cfg.h"
 #include "tree-ssa-propagate.h"
 #include "dbgcnt.h"
index 89b0517..9a84321 100644 (file)
@@ -30,10 +30,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "fold-const.h"
 #include "cfganal.h"
 #include "cfgloop.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "tree-inline.h"
-#include "gimple-iterator.h"
 #include "tree-cfg.h"
 #include "tree-into-ssa.h"
 #include "domwalk.h"
index c5b2a4f..48cab58 100644 (file)
@@ -32,10 +32,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-pretty-print.h"
 #include "fold-const.h"
 #include "stor-layout.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimplify.h"
-#include "gimple-iterator.h"
 #include "gimplify-me.h"
 #include "tree-cfg.h"
 #include "expr.h"
index cb86cc1..88a9f06 100644 (file)
@@ -35,8 +35,8 @@ along with GCC; see the file COPYING3.  If not see
    BRANCH_COST.  */
 #include "fold-const.h"
 #include "cfganal.h"
-#include "gimple-fold.h"
 #include "gimple-iterator.h"
+#include "gimple-fold.h"
 #include "gimplify-me.h"
 #include "tree-cfg.h"
 #include "tree-ssa.h"
index e2ac204..2ee00a3 100644 (file)
@@ -48,9 +48,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-pretty-print.h"
 #include "fold-const.h"
 #include "profile.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
-#include "gimple-iterator.h"
 #include "tree-cfg.h"
 #include "tree-ssa-loop-manip.h"
 #include "tree-ssa-loop-niter.h"
index 2085597..ce1df01 100644 (file)
@@ -100,8 +100,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-pretty-print.h"
 #include "alias.h"
 #include "fold-const.h"
-#include "gimple-fold.h"
 #include "gimple-iterator.h"
+#include "gimple-fold.h"
 #include "gimplify.h"
 #include "gimplify-me.h"
 #include "stor-layout.h"
index a578ce6..34d77f1 100644 (file)
@@ -34,10 +34,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-pretty-print.h"
 #include "fold-const.h"
 #include "cfganal.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimplify.h"
-#include "gimple-iterator.h"
 #include "tree-cfg.h"
 #include "tree-into-ssa.h"
 #include "tree-dfa.h"
index 7813e51..c10ffd9 100644 (file)
 #include "ssa.h"
 #include "gimple-pretty-print.h"
 #include "dumpfile.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimplify.h"
-#include "gimple-iterator.h"
 #include "tree-cfg.h"
 #include "tree-ssa.h"
 #include "tree-ssa-propagate.h"
index 43b2537..406523b 100644 (file)
@@ -38,9 +38,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "fold-const.h"
 #include "stor-layout.h"
 #include "cfganal.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
-#include "gimple-iterator.h"
 #include "gimplify-me.h"
 #include "tree-cfg.h"
 #include "tree-ssa-loop.h"
index f1bc372..ed68557 100644 (file)
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfganal.h"
 #include "tree-inline.h"
 #include "internal-fn.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimplify.h"
@@ -56,7 +57,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-propagate.h"
 #include "tree-cfg.h"
 #include "domwalk.h"
-#include "gimple-iterator.h"
 #include "gimple-match.h"
 #include "stringpool.h"
 #include "attribs.h"
index 1e5f911..bb7fe08 100644 (file)
@@ -34,10 +34,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-ssa-warn-restrict.h"
 #include "fold-const.h"
 #include "stor-layout.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
 #include "gimplify.h"
-#include "gimple-iterator.h"
 #include "gimplify-me.h"
 #include "expr.h"
 #include "tree-cfg.h"
index a362a0a..6507348 100644 (file)
@@ -30,9 +30,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "diagnostic-core.h"
 #include "fold-const.h"
 #include "stor-layout.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "gimplify.h"
-#include "gimple-iterator.h"
 #include "gimple-walk.h"
 #include "tree-ssa-loop-manip.h"
 #include "tree-into-ssa.h"
index e5bd9dc..d99e320 100644 (file)
@@ -54,10 +54,7 @@ gimplify_build3 (gimple_stmt_iterator *gsi, enum tree_code code,
                 tree type, tree a, tree b, tree c)
 {
   location_t loc = gimple_location (gsi_stmt (*gsi));
-  gimple_seq stmts = NULL;
-  tree ret = gimple_build (&stmts, loc, code, type, a, b, c);
-  gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
-  return ret;
+  return gimple_build (gsi, true, GSI_SAME_STMT, loc, code, type, a, b, c);
 }
 
 /* Build a binary operation and gimplify it.  Emit code before GSI.
@@ -68,10 +65,7 @@ gimplify_build2 (gimple_stmt_iterator *gsi, enum tree_code code,
                 tree type, tree a, tree b)
 {
   location_t loc = gimple_location (gsi_stmt (*gsi));
-  gimple_seq stmts = NULL;
-  tree ret = gimple_build (&stmts, loc, code, type, a, b);
-  gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
-  return ret;
+  return gimple_build (gsi, true, GSI_SAME_STMT, loc, code, type, a, b);
 }
 
 /* Build a unary operation and gimplify it.  Emit code before GSI.
@@ -82,10 +76,7 @@ gimplify_build1 (gimple_stmt_iterator *gsi, enum tree_code code, tree type,
                 tree a)
 {
   location_t loc = gimple_location (gsi_stmt (*gsi));
-  gimple_seq stmts = NULL;
-  tree ret = gimple_build (&stmts, loc, code, type, a);
-  gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
-  return ret;
+  return gimple_build (gsi, true, GSI_SAME_STMT, loc, code, type, a);
 }
 
 
index f74929d..6c05814 100644 (file)
@@ -1184,12 +1184,9 @@ ubsan_expand_ptr_ifn (gimple_stmt_iterator *gsip)
       gimple_set_location (g, loc);
       gsi_insert_after (&gsi2, g, GSI_NEW_STMT);
 
-      gimple_seq seq = NULL;
-      tree t = gimple_build (&seq, loc, NOP_EXPR, ssizetype, off);
-      t = gimple_build (&seq, loc, GE_EXPR, boolean_type_node,
-                       t, ssize_int (0));
-      gsi_insert_seq_before (&gsi, seq, GSI_SAME_STMT);
-      g = gimple_build_cond (NE_EXPR, t, boolean_false_node,
+      tree t = gimple_build (&gsi, true, GSI_SAME_STMT,
+                            loc, NOP_EXPR, ssizetype, off);
+      g = gimple_build_cond (GE_EXPR, t, ssize_int (0),
                             NULL_TREE, NULL_TREE);
     }
   gimple_set_location (g, loc);
index f2d95c4..b768ecd 100644 (file)
@@ -28,9 +28,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "ssa.h"
 #include "gimple-pretty-print.h"
 #include "cfganal.h"
+#include "gimple-iterator.h"
 #include "gimple-fold.h"
 #include "tree-eh.h"
-#include "gimple-iterator.h"
 #include "tree-cfg.h"
 #include "tree-ssa-loop-manip.h"
 #include "tree-ssa-loop.h"
index 301996d..2cc5084 100644 (file)
@@ -32,8 +32,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "fold-const.h"
 #include "calls.h"
 #include "cfganal.h"
-#include "gimple-fold.h"
 #include "gimple-iterator.h"
+#include "gimple-fold.h"
 #include "tree-cfg.h"
 #include "tree-ssa-loop-niter.h"
 #include "tree-ssa-loop.h"