poly_int: brig vector elements
authorRichard Sandiford <richard.sandiford@linaro.org>
Wed, 3 Jan 2018 07:17:00 +0000 (07:17 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Wed, 3 Jan 2018 07:17:00 +0000 (07:17 +0000)
This patch adds a brig-specific wrapper around TYPE_VECTOR_SUBPARTS,
since presumably it will never need to support variable vector lengths.

2018-01-03  Richard Sandiford  <richard.sandiford@linaro.org>
    Alan Hayward  <alan.hayward@arm.com>
    David Sherwood  <david.sherwood@arm.com>

gcc/brig/
* brigfrontend/brig-util.h (gccbrig_type_vector_subparts): New
function.
* brigfrontend/brig-basic-inst-handler.cc
(brig_basic_inst_handler::build_shuffle): Use it instead of
TYPE_VECTOR_SUBPARTS.
(brig_basic_inst_handler::build_unpack): Likewise.
(brig_basic_inst_handler::build_pack): Likewise.
(brig_basic_inst_handler::build_unpack_lo_or_hi): Likewise.
(brig_basic_inst_handler::operator ()): Likewise.
(brig_basic_inst_handler::build_lower_element_broadcast): Likewise.
* brigfrontend/brig-code-entry-handler.cc
(brig_code_entry_handler::get_tree_cst_for_hsa_operand): Likewise.
(brig_code_entry_handler::get_comparison_result_type): Likewise.
(brig_code_entry_handler::expand_or_call_builtin): Likewise.

Co-Authored-By: Alan Hayward <alan.hayward@arm.com>
Co-Authored-By: David Sherwood <david.sherwood@arm.com>
From-SVN: r256144

gcc/brig/ChangeLog
gcc/brig/brigfrontend/brig-basic-inst-handler.cc
gcc/brig/brigfrontend/brig-code-entry-handler.cc
gcc/brig/brigfrontend/brig-util.h

index 0bb552e41cbc115d19947df699058930706e9f5b..b4f2ec0229b5ae9fc97817afd82c78da68f6cbaf 100644 (file)
@@ -1,3 +1,22 @@
+2018-01-03  Richard Sandiford  <richard.sandiford@linaro.org>
+           Alan Hayward  <alan.hayward@arm.com>
+           David Sherwood  <david.sherwood@arm.com>
+
+       * brigfrontend/brig-util.h (gccbrig_type_vector_subparts): New
+       function.
+       * brigfrontend/brig-basic-inst-handler.cc
+       (brig_basic_inst_handler::build_shuffle): Use it instead of
+       TYPE_VECTOR_SUBPARTS.
+       (brig_basic_inst_handler::build_unpack): Likewise.
+       (brig_basic_inst_handler::build_pack): Likewise.
+       (brig_basic_inst_handler::build_unpack_lo_or_hi): Likewise.
+       (brig_basic_inst_handler::operator ()): Likewise.
+       (brig_basic_inst_handler::build_lower_element_broadcast): Likewise.
+       * brigfrontend/brig-code-entry-handler.cc
+       (brig_code_entry_handler::get_tree_cst_for_hsa_operand): Likewise.
+       (brig_code_entry_handler::get_comparison_result_type): Likewise.
+       (brig_code_entry_handler::expand_or_call_builtin): Likewise.
+
 2017-12-15  Jakub Jelinek  <jakub@redhat.com>
 
        * brig-lang.c (brig_attribute_table): Swap affects_type_identity
index ad5a41001ad0f3aea694c4473108963d6d6888c2..ad0b24bedc553054a83e9f59d2c29e626f22c260 100644 (file)
@@ -97,9 +97,10 @@ brig_basic_inst_handler::build_shuffle (tree arith_type,
      output elements can originate from any input element.  */
   vec<constructor_elt, va_gc> *mask_offset_vals = NULL;
 
+  unsigned int element_count = gccbrig_type_vector_subparts (arith_type);
+
   vec<constructor_elt, va_gc> *input_mask_vals = NULL;
-  size_t input_mask_element_size
-    = exact_log2 (TYPE_VECTOR_SUBPARTS (arith_type));
+  size_t input_mask_element_size = exact_log2 (element_count);
 
   /* Unpack the tightly packed mask elements to BIT_FIELD_REFs
      from which to construct the mask vector as understood by
@@ -109,7 +110,7 @@ brig_basic_inst_handler::build_shuffle (tree arith_type,
   tree mask_element_type
     = build_nonstandard_integer_type (input_mask_element_size, true);
 
-  for (size_t i = 0; i < TYPE_VECTOR_SUBPARTS (arith_type); ++i)
+  for (size_t i = 0; i < element_count; ++i)
     {
       tree mask_element
        = build3 (BIT_FIELD_REF, mask_element_type, mask_operand,
@@ -119,17 +120,15 @@ brig_basic_inst_handler::build_shuffle (tree arith_type,
       mask_element = convert (element_type, mask_element);
 
       tree offset;
-      if (i < TYPE_VECTOR_SUBPARTS (arith_type) / 2)
+      if (i < element_count / 2)
        offset = build_int_cst (element_type, 0);
       else
-       offset
-         = build_int_cst (element_type, TYPE_VECTOR_SUBPARTS (arith_type));
+       offset = build_int_cst (element_type, element_count);
 
       CONSTRUCTOR_APPEND_ELT (mask_offset_vals, NULL_TREE, offset);
       CONSTRUCTOR_APPEND_ELT (input_mask_vals, NULL_TREE, mask_element);
     }
-  tree mask_vec_type
-    = build_vector_type (element_type, TYPE_VECTOR_SUBPARTS (arith_type));
+  tree mask_vec_type = build_vector_type (element_type, element_count);
 
   tree mask_vec = build_constructor (mask_vec_type, input_mask_vals);
   tree offset_vec = build_constructor (mask_vec_type, mask_offset_vals);
@@ -158,7 +157,8 @@ brig_basic_inst_handler::build_unpack (tree_stl_vec &operands)
   vec<constructor_elt, va_gc> *input_mask_vals = NULL;
   vec<constructor_elt, va_gc> *and_mask_vals = NULL;
 
-  size_t element_count = TYPE_VECTOR_SUBPARTS (TREE_TYPE (operands[0]));
+  size_t element_count
+    = gccbrig_type_vector_subparts (TREE_TYPE (operands[0]));
   tree vec_type = build_vector_type (element_type, element_count);
 
   for (size_t i = 0; i < element_count; ++i)
@@ -214,7 +214,7 @@ brig_basic_inst_handler::build_pack (tree_stl_vec &operands)
      TODO: Reuse this for implementing 'bitinsert'
      without a builtin call.  */
 
-  size_t ecount = TYPE_VECTOR_SUBPARTS (TREE_TYPE (operands[0]));
+  size_t ecount = gccbrig_type_vector_subparts (TREE_TYPE (operands[0]));
   size_t vecsize = int_size_in_bytes (TREE_TYPE (operands[0])) * BITS_PER_UNIT;
   tree wide_type = build_nonstandard_integer_type (vecsize, 1);
 
@@ -276,9 +276,10 @@ brig_basic_inst_handler::build_unpack_lo_or_hi (BrigOpcode16_t brig_opcode,
 {
   tree element_type = get_unsigned_int_type (TREE_TYPE (arith_type));
   tree mask_vec_type
-    = build_vector_type (element_type, TYPE_VECTOR_SUBPARTS (arith_type));
+    = build_vector_type (element_type,
+                        gccbrig_type_vector_subparts (arith_type));
 
-  size_t element_count = TYPE_VECTOR_SUBPARTS (arith_type);
+  size_t element_count = gccbrig_type_vector_subparts (arith_type);
   vec<constructor_elt, va_gc> *input_mask_vals = NULL;
 
   size_t offset = (brig_opcode == BRIG_OPCODE_UNPACKLO) ? 0 : element_count / 2;
@@ -601,8 +602,8 @@ brig_basic_inst_handler::operator () (const BrigBase *base)
        }
 
       size_t promoted_type_size = int_size_in_bytes (promoted_type) * 8;
-
-      for (size_t i = 0; i < TYPE_VECTOR_SUBPARTS (arith_type); ++i)
+      size_t element_count = gccbrig_type_vector_subparts (arith_type);
+      for (size_t i = 0; i < element_count; ++i)
        {
          tree operand0 = convert (promoted_type, operand0_elements.at (i));
          tree operand1 = convert (promoted_type, operand1_elements.at (i));
@@ -709,7 +710,8 @@ brig_basic_inst_handler::build_lower_element_broadcast (tree vec_operand)
   tree element_type = TREE_TYPE (TREE_TYPE (vec_operand));
   size_t esize = 8 * int_size_in_bytes (element_type);
 
-  size_t element_count = TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec_operand));
+  size_t element_count
+    = gccbrig_type_vector_subparts (TREE_TYPE (vec_operand));
   tree mask_inner_type = build_nonstandard_integer_type (esize, 1);
   vec<constructor_elt, va_gc> *constructor_vals = NULL;
 
index 923a4541e0b38e5d7859d5dbd82f7812518a2687..fa4da9fb24a8b395a81c4b35acda4760807d6a6a 100644 (file)
@@ -638,7 +638,8 @@ brig_code_entry_handler::get_tree_cst_for_hsa_operand
        {
          /* In case of vector type elements (or sole vectors),
             create a vector ctor.  */
-         size_t element_count = TYPE_VECTOR_SUBPARTS (tree_element_type);
+         size_t element_count
+           = gccbrig_type_vector_subparts (tree_element_type);
          if (bytes_left < scalar_element_size * element_count)
            fatal_error (UNKNOWN_LOCATION,
                         "Not enough bytes left for the initializer "
@@ -841,7 +842,7 @@ brig_code_entry_handler::get_comparison_result_type (tree source_type)
       size_t element_size = int_size_in_bytes (TREE_TYPE (source_type));
       return build_vector_type
        (build_nonstandard_boolean_type (element_size * BITS_PER_UNIT),
-        TYPE_VECTOR_SUBPARTS (source_type));
+        gccbrig_type_vector_subparts (source_type));
     }
   else
     return gccbrig_tree_type_for_hsa_type (BRIG_TYPE_B1);
@@ -946,7 +947,8 @@ brig_code_entry_handler::expand_or_call_builtin (BrigOpcode16_t brig_opcode,
 
       tree_stl_vec result_elements;
 
-      for (size_t i = 0; i < TYPE_VECTOR_SUBPARTS (arith_type); ++i)
+      size_t element_count = gccbrig_type_vector_subparts (arith_type);
+      for (size_t i = 0; i < element_count; ++i)
        {
          tree_stl_vec call_operands;
          if (operand0_elements.size () > 0)
index d47470f0c4032a2a4d3c9bbecf4134128605d1f5..3dd2c6e93d6289517ebc97759d08fbc74765d850 100644 (file)
@@ -107,4 +107,12 @@ std::string gccbrig_hsa_reg_name_from_id (size_t reg_hash);
 
 void gccbrig_print_reg_use_info (FILE *dump, const regs_use_index &info);
 
+/* Return the number of elements in a VECTOR_TYPE.  BRIG does not support
+   variable-length vectors.  */
+inline unsigned HOST_WIDE_INT
+gccbrig_type_vector_subparts (const_tree type)
+{
+  return TYPE_VECTOR_SUBPARTS (type);
+}
+
 #endif