diff mbox

[hsa] Switch from bittype_for_type to hsa_type_bit_size

Message ID 20150619190545.GT18873@virgil.suse
State New
Headers show

Commit Message

Martin Jambor June 19, 2015, 7:05 p.m. UTC
Hi,

except for one use, from bittype_for_type was used as a poor-man's
type size function.  That is confusing, so I added a real type size
function.  The new implementation of hsa_bittype_for_type then uses
that as its basis too.

Martin

2015-06-18  Martin Jambor  <mjambor@suse.cz>

	* hsa.c (hsa_type_bit_size): New function.
	(hsa_bittype_for_type): Likewise.
	* hsa-brig.c (get_alignment): Use hsa_type_bit_size.
	(bittype_for_type): removed.
	* hsa-gen.c (hsa_needs_cvt): Use hsa_type_bit_size.
	(gen_address_calculation): Likewise.
	(hsa_build_append_simple_mov): Likewise.
	(gen_hsa_insns_for_store): Likewise.
	(gen_hsa_insns_for_call): Likewise.
---
 gcc/ChangeLog.hsa | 12 ++++++++
 gcc/hsa-brig.c    | 81 +++++--------------------------------------------
 gcc/hsa-gen.c     | 31 ++++++++++---------
 gcc/hsa.c         | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gcc/hsa.h         |  2 ++
 5 files changed, 129 insertions(+), 88 deletions(-)
diff mbox

Patch

diff --git a/gcc/hsa-brig.c b/gcc/hsa-brig.c
index bb4a2c1..e17d941 100644
--- a/gcc/hsa-brig.c
+++ b/gcc/hsa-brig.c
@@ -445,20 +445,20 @@  brig_release_data (void)
 static BrigAlignment8_t
 get_alignment (BrigType16_t type)
 {
-  BrigType16_t bit_type ;
-  bit_type = bittype_for_type (type) ;
+  unsigned bit_size ;
+  bit_size = hsa_type_bit_size (type) ;
 
-  if (bit_type == BRIG_TYPE_B1)
+  if (bit_size == 1)
     return BRIG_ALIGNMENT_1;
-  if (bit_type == BRIG_TYPE_B8)
+  if (bit_size == 8)
     return BRIG_ALIGNMENT_1;
-  if (bit_type == BRIG_TYPE_B16)
+  if (bit_size == 16)
     return BRIG_ALIGNMENT_2;
-  if (bit_type == BRIG_TYPE_B32)
+  if (bit_size == 32)
     return BRIG_ALIGNMENT_4;
-  if (bit_type == BRIG_TYPE_B64)
+  if (bit_size == 64)
     return BRIG_ALIGNMENT_8;
-  if (bit_type == BRIG_TYPE_B128)
+  if (bit_size == 128)
     return BRIG_ALIGNMENT_16;
   gcc_unreachable ();
 }
@@ -621,71 +621,6 @@  emit_bb_label_directive (hsa_bb *hbb)
   brig_insn_count++;
 }
 
-BrigType16_t
-bittype_for_type (BrigType16_t t)
-{
-  switch (t)
-    {
-    case BRIG_TYPE_B1:
-      return BRIG_TYPE_B1;
-
-    case BRIG_TYPE_U8:
-    case BRIG_TYPE_S8:
-    case BRIG_TYPE_B8:
-      return BRIG_TYPE_B8;
-
-    case BRIG_TYPE_U16:
-    case BRIG_TYPE_S16:
-    case BRIG_TYPE_B16:
-    case BRIG_TYPE_F16:
-      return BRIG_TYPE_B16;
-
-    case BRIG_TYPE_U32:
-    case BRIG_TYPE_S32:
-    case BRIG_TYPE_B32:
-    case BRIG_TYPE_F32:
-    case BRIG_TYPE_U8X4:
-    case BRIG_TYPE_U16X2:
-    case BRIG_TYPE_S8X4:
-    case BRIG_TYPE_S16X2:
-    case BRIG_TYPE_F16X2:
-      return BRIG_TYPE_B32;
-
-    case BRIG_TYPE_U64:
-    case BRIG_TYPE_S64:
-    case BRIG_TYPE_F64:
-    case BRIG_TYPE_B64:
-    case BRIG_TYPE_U8X8:
-    case BRIG_TYPE_U16X4:
-    case BRIG_TYPE_U32X2:
-    case BRIG_TYPE_S8X8:
-    case BRIG_TYPE_S16X4:
-    case BRIG_TYPE_S32X2:
-    case BRIG_TYPE_F16X4:
-    case BRIG_TYPE_F32X2:
-
-      return BRIG_TYPE_B64;
-
-    case BRIG_TYPE_B128:
-    case BRIG_TYPE_U8X16:
-    case BRIG_TYPE_U16X8:
-    case BRIG_TYPE_U32X4:
-    case BRIG_TYPE_U64X2:
-    case BRIG_TYPE_S8X16:
-    case BRIG_TYPE_S16X8:
-    case BRIG_TYPE_S32X4:
-    case BRIG_TYPE_S64X2:
-    case BRIG_TYPE_F16X8:
-    case BRIG_TYPE_F32X4:
-    case BRIG_TYPE_F64X2:
-      return BRIG_TYPE_B128;
-
-    default:
-      gcc_assert (seen_error ());
-      return t;
-    }
-}
-
 /* Map a normal HSAIL type to the type of the equivalent BRIG operand
    holding such, for constants and registers.  */
 
diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 7be4db7..9fb8096 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -401,9 +401,8 @@  hsa_needs_cvt (BrigType16_t dtype, BrigType16_t stype)
   /* float <-> int conversions are real converts.  */
   if (hsa_type_float_p (dtype) != hsa_type_float_p (stype))
     return true;
-  /* When both types have different size (equivalent to different
-     underlying bit types), then we need CVT as well.  */
-  if (bittype_for_type (dtype) != bittype_for_type (stype))
+  /* When both types have different size, then we need CVT as well.  */
+  if (hsa_type_bit_size (dtype) != hsa_type_bit_size (stype))
     return true;
   return false;
 }
@@ -816,8 +815,8 @@  gen_address_calculation (tree exp, hsa_bb *hbb, vec <hsa_op_reg_p> ssa_map,
        hsa_op_immed *imm = hsa_alloc_immed_op (exp);
        if (addrtype != imm->type)
 	 {
-	   gcc_assert (bittype_for_type (addrtype)
-		       > bittype_for_type (imm->type));
+	   gcc_assert (hsa_type_bit_size (addrtype)
+		       > hsa_type_bit_size (imm->type));
 	   imm->type = addrtype;
 	 }
        return imm;
@@ -1181,12 +1180,13 @@  hsa_build_append_simple_mov (hsa_op_reg *dest, hsa_op_base *src, hsa_bb *hbb)
   insn->operands[1] = src;
   if (hsa_op_reg *sreg = dyn_cast <hsa_op_reg *> (src))
     {
-      gcc_assert (bittype_for_type (dest->type) == bittype_for_type (sreg->type));
+      gcc_assert (hsa_type_bit_size (dest->type)
+		  == hsa_type_bit_size (sreg->type));
       sreg->uses.safe_push (insn);
     }
   else
-    gcc_assert (bittype_for_type (dest->type)
-		== bittype_for_type (as_a <hsa_op_immed *> (src)->type));
+    gcc_assert (hsa_type_bit_size (dest->type)
+		== hsa_type_bit_size (as_a <hsa_op_immed *> (src)->type));
   set_reg_def (dest, insn);
   hsa_append_insn (hbb, insn);
 }
@@ -1280,17 +1280,17 @@  gen_hsa_insns_for_store (tree lhs, hsa_op_base *src, hsa_bb *hbb,
 	{
 	  /* ...and all vector immediates apparently need to be vectors of
 	     unsigned bytes. */
-	  BrigType16_t bt = bittype_for_type (imm->type);
-	  gcc_assert (bt == bittype_for_type (mem->type));
-	  switch (bt)
+	  unsigned bs = hsa_type_bit_size (imm->type);
+	  gcc_assert (bs == hsa_type_bit_size (mem->type));
+	  switch (bs)
 	    {
-	    case BRIG_TYPE_B32:
+	    case 32:
 	      imm->type = BRIG_TYPE_U8X4;
 	      break;
-	    case BRIG_TYPE_B64:
+	    case 64:
 	      imm->type = BRIG_TYPE_U8X8;
 	      break;
-	    case BRIG_TYPE_B128:
+	    case 128:
 	      imm->type = BRIG_TYPE_U8X16;
 	      break;
 	    default:
@@ -1954,7 +1954,8 @@  specialop:
 	atominsn->opcode = BRIG_OPCODE_ATOMIC;
 	/* Should check what the memory scope is */
 	atominsn->memoryscope = BRIG_MEMORY_SCOPE_WORKGROUP;
-	atominsn->type = bittype_for_type (hsa_type_for_scalar_tree_type (TREE_TYPE (lhs), false));
+	atominsn->type = hsa_bittype_for_type
+	  (hsa_type_for_scalar_tree_type (TREE_TYPE (lhs), false));
 	atominsn->operands[0] = dest;
 	atominsn->operands[1] = addr;
 	atominsn->operands[2]
diff --git a/gcc/hsa.c b/gcc/hsa.c
index 966949b..3212205 100644
--- a/gcc/hsa.c
+++ b/gcc/hsa.c
@@ -156,6 +156,97 @@  hsa_opcode_op_output_p (BrigOpcode16_t opcode, int opnum)
     }
 }
 
+/* Return size of HSA type T in bits.  */
+
+unsigned
+hsa_type_bit_size (BrigType16_t t)
+{
+  switch (t)
+    {
+    case BRIG_TYPE_B1:
+      return 1;
+
+    case BRIG_TYPE_U8:
+    case BRIG_TYPE_S8:
+    case BRIG_TYPE_B8:
+      return 8;
+
+    case BRIG_TYPE_U16:
+    case BRIG_TYPE_S16:
+    case BRIG_TYPE_B16:
+    case BRIG_TYPE_F16:
+      return 16;
+
+    case BRIG_TYPE_U32:
+    case BRIG_TYPE_S32:
+    case BRIG_TYPE_B32:
+    case BRIG_TYPE_F32:
+    case BRIG_TYPE_U8X4:
+    case BRIG_TYPE_U16X2:
+    case BRIG_TYPE_S8X4:
+    case BRIG_TYPE_S16X2:
+    case BRIG_TYPE_F16X2:
+      return 32;
+
+    case BRIG_TYPE_U64:
+    case BRIG_TYPE_S64:
+    case BRIG_TYPE_F64:
+    case BRIG_TYPE_B64:
+    case BRIG_TYPE_U8X8:
+    case BRIG_TYPE_U16X4:
+    case BRIG_TYPE_U32X2:
+    case BRIG_TYPE_S8X8:
+    case BRIG_TYPE_S16X4:
+    case BRIG_TYPE_S32X2:
+    case BRIG_TYPE_F16X4:
+    case BRIG_TYPE_F32X2:
+
+      return 64;
+
+    case BRIG_TYPE_B128:
+    case BRIG_TYPE_U8X16:
+    case BRIG_TYPE_U16X8:
+    case BRIG_TYPE_U32X4:
+    case BRIG_TYPE_U64X2:
+    case BRIG_TYPE_S8X16:
+    case BRIG_TYPE_S16X8:
+    case BRIG_TYPE_S32X4:
+    case BRIG_TYPE_S64X2:
+    case BRIG_TYPE_F16X8:
+    case BRIG_TYPE_F32X4:
+    case BRIG_TYPE_F64X2:
+      return 128;
+
+    default:
+      gcc_assert (seen_error ());
+      return t;
+    }
+}
+
+/* Return HSA bit-type with the same size as the type T.  */
+
+BrigType16_t
+hsa_bittype_for_type (BrigType16_t t)
+{
+  switch (hsa_type_bit_size (t))
+    {
+    case 1:
+      return BRIG_TYPE_B1;
+    case 8:
+      return BRIG_TYPE_B8;
+    case 16:
+      return BRIG_TYPE_B16;
+    case 32:
+      return BRIG_TYPE_B32;
+    case 64:
+      return BRIG_TYPE_B64;
+    case 128:
+      return BRIG_TYPE_B128;
+    default:
+      return t;
+    }
+}
+
 /* Create a mapping between the original function DECL and kernel name NAME.  */
 
 void
diff --git a/gcc/hsa.h b/gcc/hsa.h
index e8dec42..c0a8ead 100644
--- a/gcc/hsa.h
+++ b/gcc/hsa.h
@@ -612,6 +612,8 @@  void hsa_deinit_compilation_unit_data (void);
 bool hsa_machine_large_p (void);
 bool hsa_full_profile_p (void);
 bool hsa_opcode_op_output_p (BrigOpcode16_t, int);
+unsigned hsa_type_bit_size (BrigType16_t t);
+BrigType16_t hsa_bittype_for_type (BrigType16_t t);
 void hsa_add_kern_decl_mapping (tree decl, char *name);
 unsigned hsa_get_number_decl_kernel_mappings (void);
 tree hsa_get_decl_kernel_mapping_decl (unsigned i);