PR ipa/pr67600
[platform/upstream/gcc.git] / gcc / tree-vectorizer.c
index 9d17802..3e6fd35 100644 (file)
@@ -58,31 +58,20 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "dumpfile.h"
-#include "tm.h"
-#include "alias.h"
-#include "symtab.h"
+#include "backend.h"
+#include "predict.h"
 #include "tree.h"
+#include "gimple.h"
+#include "hard-reg-set.h"
+#include "ssa.h"
+#include "alias.h"
 #include "fold-const.h"
 #include "stor-layout.h"
 #include "tree-pretty-print.h"
-#include "predict.h"
-#include "hard-reg-set.h"
-#include "function.h"
-#include "dominance.h"
-#include "cfg.h"
-#include "basic-block.h"
-#include "tree-ssa-alias.h"
 #include "internal-fn.h"
-#include "gimple-expr.h"
-#include "gimple.h"
 #include "gimple-iterator.h"
 #include "gimple-walk.h"
-#include "gimple-ssa.h"
-#include "plugin-api.h"
-#include "ipa-ref.h"
 #include "cgraph.h"
-#include "tree-phinodes.h"
-#include "ssa-iterators.h"
 #include "tree-ssa-loop-manip.h"
 #include "tree-cfg.h"
 #include "cfgloop.h"
@@ -98,18 +87,16 @@ along with GCC; see the file COPYING3.  If not see
 source_location vect_location;
 
 /* Vector mapping GIMPLE stmt to stmt_vec_info. */
-vec<vec_void_p> stmt_vec_info_vec;
+vec<stmt_vec_info> stmt_vec_info_vec;
 \f
 /* For mapping simduid to vectorization factor.  */
 
-struct simduid_to_vf : typed_free_remove<simduid_to_vf>
+struct simduid_to_vf : free_ptr_hash<simduid_to_vf>
 {
   unsigned int simduid;
   int vf;
 
   /* hash_table support.  */
-  typedef simduid_to_vf *value_type;
-  typedef simduid_to_vf *compare_type;
   static inline hashval_t hash (const simduid_to_vf *);
   static inline int equal (const simduid_to_vf *, const simduid_to_vf *);
 };
@@ -138,14 +125,12 @@ simduid_to_vf::equal (const simduid_to_vf *p1, const simduid_to_vf *p2)
    This hash maps from the OMP simd array (D.1737[]) to DECL_UID of
    simduid.0.  */
 
-struct simd_array_to_simduid : typed_free_remove<simd_array_to_simduid>
+struct simd_array_to_simduid : free_ptr_hash<simd_array_to_simduid>
 {
   tree decl;
   unsigned int simduid;
 
   /* hash_table support.  */
-  typedef simd_array_to_simduid *value_type;
-  typedef simd_array_to_simduid *compare_type;
   static inline hashval_t hash (const simd_array_to_simduid *);
   static inline int equal (const simd_array_to_simduid *,
                           const simd_array_to_simduid *);
@@ -164,8 +149,9 @@ simd_array_to_simduid::equal (const simd_array_to_simduid *p1,
   return p1->decl == p2->decl;
 }
 
-/* Fold IFN_GOMP_SIMD_LANE, IFN_GOMP_SIMD_VF and IFN_GOMP_SIMD_LAST_LANE
-   into their corresponding constants.  */
+/* Fold IFN_GOMP_SIMD_LANE, IFN_GOMP_SIMD_VF, IFN_GOMP_SIMD_LAST_LANE,
+   into their corresponding constants and remove
+   IFN_GOMP_SIMD_ORDERED_{START,END}.  */
 
 static void
 adjust_simduid_builtins (hash_table<simduid_to_vf> *htab)
@@ -176,15 +162,18 @@ adjust_simduid_builtins (hash_table<simduid_to_vf> *htab)
     {
       gimple_stmt_iterator i;
 
-      for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i))
+      for (i = gsi_start_bb (bb); !gsi_end_p (i); )
        {
          unsigned int vf = 1;
          enum internal_fn ifn;
-         gimple stmt = gsi_stmt (i);
+         gimple *stmt = gsi_stmt (i);
          tree t;
          if (!is_gimple_call (stmt)
              || !gimple_call_internal_p (stmt))
-           continue;
+           {
+             gsi_next (&i);
+             continue;
+           }
          ifn = gimple_call_internal_fn (stmt);
          switch (ifn)
            {
@@ -192,7 +181,13 @@ adjust_simduid_builtins (hash_table<simduid_to_vf> *htab)
            case IFN_GOMP_SIMD_VF:
            case IFN_GOMP_SIMD_LAST_LANE:
              break;
+           case IFN_GOMP_SIMD_ORDERED_START:
+           case IFN_GOMP_SIMD_ORDERED_END:
+             gsi_remove (&i, true);
+             unlink_stmt_vdef (stmt);
+             continue;
            default:
+             gsi_next (&i);
              continue;
            }
          tree arg = gimple_call_arg (stmt, 0);
@@ -221,6 +216,7 @@ adjust_simduid_builtins (hash_table<simduid_to_vf> *htab)
              gcc_unreachable ();
            }
          update_call_from_tree (&i, t);
+         gsi_next (&i);
        }
     }
 }
@@ -285,7 +281,7 @@ note_simd_array_uses (hash_table<simd_array_to_simduid> **htab)
   FOR_EACH_BB_FN (bb, cfun)
     for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
       {
-       gimple stmt = gsi_stmt (gsi);
+       gimple *stmt = gsi_stmt (gsi);
        if (!is_gimple_call (stmt) || !gimple_call_internal_p (stmt))
          continue;
        switch (gimple_call_internal_fn (stmt))
@@ -301,7 +297,7 @@ note_simd_array_uses (hash_table<simd_array_to_simduid> **htab)
        if (lhs == NULL_TREE)
          continue;
        imm_use_iterator use_iter;
-       gimple use_stmt;
+       gimple *use_stmt;
        ns.simduid = DECL_UID (SSA_NAME_VAR (gimple_call_arg (stmt, 0)));
        FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, lhs)
          if (!is_gimple_debug (use_stmt))
@@ -344,36 +340,30 @@ shrink_simd_arrays
 /* A helper function to free data refs.  */
 
 void
-vect_destroy_datarefs (loop_vec_info loop_vinfo, bb_vec_info bb_vinfo)
+vect_destroy_datarefs (vec_info *vinfo)
 {
-  vec<data_reference_p> datarefs;
   struct data_reference *dr;
   unsigned int i;
 
- if (loop_vinfo)
-    datarefs = LOOP_VINFO_DATAREFS (loop_vinfo);
-  else
-    datarefs = BB_VINFO_DATAREFS (bb_vinfo);
-
-  FOR_EACH_VEC_ELT (datarefs, i, dr)
+  FOR_EACH_VEC_ELT (vinfo->datarefs, i, dr)
     if (dr->aux)
       {
         free (dr->aux);
         dr->aux = NULL;
       }
 
-  free_data_refs (datarefs);
+  free_data_refs (vinfo->datarefs);
 }
 
 
 /* If LOOP has been versioned during ifcvt, return the internal call
    guarding it.  */
 
-static gimple
+static gimple *
 vect_loop_vectorized_call (struct loop *loop)
 {
   basic_block bb = loop_preheader_edge (loop)->src;
-  gimple g;
+  gimple *g;
   do
     {
       g = last_stmt (bb);
@@ -406,12 +396,12 @@ vect_loop_vectorized_call (struct loop *loop)
    update any immediate uses of it's LHS.  */
 
 static void
-fold_loop_vectorized_call (gimple g, tree value)
+fold_loop_vectorized_call (gimple *g, tree value)
 {
   tree lhs = gimple_call_lhs (g);
   use_operand_p use_p;
   imm_use_iterator iter;
-  gimple use_stmt;
+  gimple *use_stmt;
   gimple_stmt_iterator gsi = gsi_for_stmt (g);
 
   update_call_from_tree (&gsi, value);
@@ -426,7 +416,7 @@ fold_loop_vectorized_call (gimple g, tree value)
    represented by LOOP_VINFO. LOOP_VECTORIZED_CALL is the internal
    call guarding the loop which has been if converted.  */
 static void
-set_uid_loop_bbs (loop_vec_info loop_vinfo, gimple loop_vectorized_call)
+set_uid_loop_bbs (loop_vec_info loop_vinfo, gimple *loop_vectorized_call)
 {
   tree arg = gimple_call_arg (loop_vectorized_call, 1);
   basic_block *bbs;
@@ -444,12 +434,12 @@ set_uid_loop_bbs (loop_vec_info loop_vinfo, gimple loop_vectorized_call)
       gimple_stmt_iterator gsi;
       for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
        {
-         gimple phi = gsi_stmt (gsi);
+         gimple *phi = gsi_stmt (gsi);
          gimple_set_uid (phi, 0);
        }
       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
        {
-         gimple stmt = gsi_stmt (gsi);
+         gimple *stmt = gsi_stmt (gsi);
          gimple_set_uid (stmt, 0);
        }
     }
@@ -512,7 +502,7 @@ vectorize_loops (void)
         if (!dbg_cnt (vect_loop))
          break;
 
-       gimple loop_vectorized_call = vect_loop_vectorized_call (loop);
+       gimple *loop_vectorized_call = vect_loop_vectorized_call (loop);
        if (loop_vectorized_call)
          set_uid_loop_bbs (loop_vinfo, loop_vectorized_call);
         if (LOCATION_LOCUS (vect_location) != UNKNOWN_LOCATION
@@ -560,7 +550,7 @@ vectorize_loops (void)
        loop = get_loop (cfun, i);
        if (loop && loop->dont_vectorize)
          {
-           gimple g = vect_loop_vectorized_call (loop);
+           gimple *g = vect_loop_vectorized_call (loop);
            if (g)
              {
                fold_loop_vectorized_call (g, boolean_false_node);
@@ -583,7 +573,7 @@ vectorize_loops (void)
 
   free_stmt_vec_info_vec ();
 
-  /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE} builtins.  */
+  /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE,ORDERED_{START,END}} builtins.  */
   if (cfun->has_simduid_loops)
     adjust_simduid_builtins (simduid_to_vf_htab);
 
@@ -645,7 +635,7 @@ pass_simduid_cleanup::execute (function *fun)
 
   note_simd_array_uses (&simd_array_to_simduid_htab);
 
-  /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE} builtins.  */
+  /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE,ORDERED_{START,END}} builtins.  */
   adjust_simduid_builtins (NULL);
 
   /* Shrink any "omp array simd" temporary arrays to the