[hsa-branch] Remove unnecessary operators

Martin Jambor mjambor@suse.cz
Tue Aug 9 14:28:00 GMT 2016


Hi,

since the HSA branch switched to a simple obstack from alloc-pools, it
is not necessary to have a separate new operator for each instruction
kind and it is enough if the common ancestor has one.  Therefore, this
patch removes them.  Similarly, I learned that it is enough to make the
delete operator private in the ancestor to make inaccessible in the
descendants so I removed those as well.

Unlike instructions, not all operand kinds use obstacks, so we have to
have the operands in those that do.  But at least there are fewer
operand kinds than instruction kinds.

Thanks,

Martin

2016-08-04  Martin Jambor  <mjambor@suse.cz>

	* hsa.h (hsa_insn_phi): Removed new and delete operators.
	(hsa_insn_br): Likewise.
	(hsa_insn_cbr): Likewise.
	(hsa_insn_sbr): Likewise.
	(hsa_insn_cmp): Likewise.
	(hsa_insn_mem): Likewise.
	(hsa_insn_atomic): Likewise.
	(hsa_insn_signal): Likewise.
	(hsa_insn_seg): Likewise.
	(hsa_insn_call): Likewise.
	(hsa_insn_arg_block): Likewise.
	(hsa_insn_comment): Likewise.
	(hsa_insn_srctype): Likewise.
	(hsa_insn_packed): Likewise.
	(hsa_insn_cvt): Likewise.
	(hsa_insn_alloca): Likewise.

	* hsa-gen.c (hsa_insn_phi::operator new): Removed.
	(hsa_insn_br::operator new): Likewise.
	(hsa_insn_cbr::operator new): Likewise.
	(hsa_insn_sbr::operator new): Likewise.
	(hsa_insn_cmp::operator new): Likewise.
	(hsa_insn_mem::operator new): Likewise.
	(hsa_insn_atomic::operator new): Likewise.
	(hsa_insn_signal::operator new): Likewise.
	(hsa_insn_seg::operator new): Likewise.
	(hsa_insn_call::operator new): Likewise.
	(hsa_insn_arg_block::operator new): Likewise.
	(hsa_insn_comment::operator new): Likewise.
	(hsa_insn_srctype::operator new): Likewise.
	(hsa_insn_packed::operator new): Likewise.
	(hsa_insn_cvt::operator new): Likewise.
	(hsa_insn_alloca::operator new): Likewise.
---
 gcc/hsa-gen.c | 128 ----------------------------------------------------------
 gcc/hsa.h     |  70 --------------------------------
 2 files changed, 198 deletions(-)

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index c578294..a9f4a8f 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -1452,14 +1452,6 @@ hsa_insn_phi::hsa_insn_phi (unsigned nops, hsa_op_reg *dst)
   dst->set_definition (this);
 }
 
-/* New operator to allocate PHI instruction from obstack.  */
-
-void *
-hsa_insn_phi::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 /* Constructor of class representing instructions for control flow and
    sychronization,   */
 
@@ -1472,14 +1464,6 @@ hsa_insn_br::hsa_insn_br (unsigned nops, int opc, BrigType16_t t,
 {
 }
 
-/* New operator to allocate branch instruction from obstack.  */
-
-void *
-hsa_insn_br::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 /* Constructor of class representing instruction for conditional jump, CTRL is
    the control register determining whether the jump will be carried out, the
    new instruction is automatically added to its uses list.  */
@@ -1489,14 +1473,6 @@ hsa_insn_cbr::hsa_insn_cbr (hsa_op_reg *ctrl)
 {
 }
 
-/* New operator to allocate branch instruction from obstack.  */
-
-void *
-hsa_insn_cbr::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 /* Constructor of class representing instruction for switch jump, CTRL is
    the index register.  */
 
@@ -1507,14 +1483,6 @@ hsa_insn_sbr::hsa_insn_sbr (hsa_op_reg *index, unsigned jump_count)
 {
 }
 
-/* New operator to allocate switch branch instruction from obstack.  */
-
-void *
-hsa_insn_sbr::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 /* Replace all occurrences of OLD_BB with NEW_BB in the statements
    jump table.  */
 
@@ -1541,14 +1509,6 @@ hsa_insn_cmp::hsa_insn_cmp (BrigCompareOperation8_t cmp, BrigType16_t t,
 {
 }
 
-/* New operator to allocate compare instruction from obstack.  */
-
-void *
-hsa_insn_cmp::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 /* Constructor of classes representing memory accesses.  OPC is the opcode (must
    be BRIG_OPCODE_ST or BRIG_OPCODE_LD) and T is the type.  The instruction
    operands are provided as ARG0 and ARG1.  */
@@ -1574,14 +1534,6 @@ hsa_insn_mem::hsa_insn_mem (unsigned nops, int opc, BrigType16_t t,
 {
 }
 
-/* New operator to allocate memory instruction from obstack.  */
-
-void *
-hsa_insn_mem::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 /* Constructor of class representing atomic instructions.  OPC is the principal
    opcode, AOP is the specific atomic operation opcode.  T is the type of the
    instruction.  The instruction operands are provided as ARG[0-3].  */
@@ -1602,14 +1554,6 @@ hsa_insn_atomic::hsa_insn_atomic (int nops, int opc,
 		       opc == BRIG_OPCODE_SIGNALNORET);
 }
 
-/* New operator to allocate signal instruction from obstack.  */
-
-void *
-hsa_insn_atomic::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 /* Constructor of class representing signal instructions.  OPC is the prinicpal
    opcode, SOP is the specific signal operation opcode.  T is the type of the
    instruction.  The instruction operands are provided as ARG[0-3].  */
@@ -1624,14 +1568,6 @@ hsa_insn_signal::hsa_insn_signal (int nops, int opc,
 {
 }
 
-/* New operator to allocate signal instruction from obstack.  */
-
-void *
-hsa_insn_signal::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 /* Constructor of class representing segment conversion instructions.  OPC is
    the opcode which must be either BRIG_OPCODE_STOF or BRIG_OPCODE_FTOS.  DEST
    and SRCT are destination and source types respectively, SEG is the segment
@@ -1647,14 +1583,6 @@ hsa_insn_seg::hsa_insn_seg (int opc, BrigType16_t dest, BrigType16_t srct,
   gcc_checking_assert (opc == BRIG_OPCODE_STOF || opc == BRIG_OPCODE_FTOS);
 }
 
-/* New operator to allocate address conversion instruction from obstack.  */
-
-void *
-hsa_insn_seg::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 /* Constructor of class representing a call instruction.  CALLEE is the tree
    representation of the function being called.  */
 
@@ -1671,14 +1599,6 @@ hsa_insn_call::hsa_insn_call (hsa_internal_fn *fn)
 {
 }
 
-/* New operator to allocate call instruction from obstack.  */
-
-void *
-hsa_insn_call::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 hsa_insn_call::~hsa_insn_call ()
 {
   for (unsigned i = 0; i < m_input_args.length (); i++)
@@ -1699,14 +1619,6 @@ hsa_insn_arg_block::hsa_insn_arg_block (BrigKind brig_kind,
 {
 }
 
-/* New operator to allocate argument block instruction from obstack.  */
-
-void *
-hsa_insn_arg_block::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 hsa_insn_comment::hsa_insn_comment (const char *s)
   : hsa_insn_basic (0, BRIG_KIND_DIRECTIVE_COMMENT)
 {
@@ -1718,14 +1630,6 @@ hsa_insn_comment::hsa_insn_comment (const char *s)
   m_comment = buf;
 }
 
-/* New operator to allocate comment instruction from obstack.  */
-
-void *
-hsa_insn_comment::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 hsa_insn_comment::~hsa_insn_comment ()
 {
   gcc_checking_assert (m_comment);
@@ -1744,14 +1648,6 @@ hsa_insn_queue::hsa_insn_queue (int nops, int opcode, BrigSegment segment,
 {
 }
 
-/* New operator to allocate source type instruction from obstack.  */
-
-void *
-hsa_insn_srctype::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 /* Constructor of class representing the source type instruction in HSAIL.  */
 
 hsa_insn_srctype::hsa_insn_srctype (int nops, BrigOpcode opcode,
@@ -1762,14 +1658,6 @@ hsa_insn_srctype::hsa_insn_srctype (int nops, BrigOpcode opcode,
     m_source_type (srct)
 {}
 
-/* New operator to allocate packed instruction from obstack.  */
-
-void *
-hsa_insn_packed::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 /* Constructor of class representing the packed instruction in HSAIL.  */
 
 hsa_insn_packed::hsa_insn_packed (int nops, BrigOpcode opcode,
@@ -1781,14 +1669,6 @@ hsa_insn_packed::hsa_insn_packed (int nops, BrigOpcode opcode,
   m_operand_list = new hsa_op_operand_list (nops - 1);
 }
 
-/* New operator to allocate convert instruction from obstack.  */
-
-void *
-hsa_insn_cvt::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 /* Constructor of class representing the convert instruction in HSAIL.  */
 
 hsa_insn_cvt::hsa_insn_cvt (hsa_op_with_type *dest, hsa_op_with_type *src)
@@ -1796,14 +1676,6 @@ hsa_insn_cvt::hsa_insn_cvt (hsa_op_with_type *dest, hsa_op_with_type *src)
 {
 }
 
-/* New operator to allocate alloca from obstack.  */
-
-void *
-hsa_insn_alloca::operator new (size_t size)
-{
-  return obstack_alloc (&hsa_obstack, size);
-}
-
 /* Constructor of class representing the alloca in HSAIL.  */
 
 hsa_insn_alloca::hsa_insn_alloca (hsa_op_with_type *dest,
diff --git a/gcc/hsa.h b/gcc/hsa.h
index 242103c..588c85a 100644
--- a/gcc/hsa.h
+++ b/gcc/hsa.h
@@ -487,17 +487,12 @@ class hsa_insn_phi : public hsa_insn_basic
 public:
   hsa_insn_phi (unsigned nops, hsa_op_reg *dst);
 
-  void *operator new (size_t);
-
   /* Destination.  */
   hsa_op_reg *m_dest;
 
 private:
   /* Make the default constructor inaccessible.  */
   hsa_insn_phi () : hsa_insn_basic (1, HSA_OPCODE_PHI) {}
-  /* All objects are deallocated by destroying their pool, so make delete
-     inaccessible too.  */
-  void operator delete (void *) {}
 };
 
 /* Report whether or not P is a PHI node.  */
@@ -518,17 +513,12 @@ public:
 	       hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
 	       hsa_op_base *arg2 = NULL, hsa_op_base *arg3 = NULL);
 
-  void *operator new (size_t);
-
   /* Number of work-items affected in the same way by the instruction.  */
   BrigWidth8_t m_width;
 
 private:
   /* Make the default constructor inaccessible.  */
   hsa_insn_br () : hsa_insn_basic (0, BRIG_OPCODE_BR) {}
-  /* All objects are deallocated by destroying their pool, so make delete
-     inaccessible too.  */
-  void operator delete (void *) {}
 };
 
 /* Return true if P is a branching/synchronization instruction.  */
@@ -551,15 +541,10 @@ class hsa_insn_cbr : public hsa_insn_br
 public:
   hsa_insn_cbr (hsa_op_reg *ctrl);
 
-  void *operator new (size_t);
-
 private:
   /* Make the default constructor inaccessible.  */
   hsa_insn_cbr () : hsa_insn_br (0, BRIG_OPCODE_CBR, BRIG_TYPE_B1,
 				 BRIG_WIDTH_1) {}
-  /* All objects are deallocated by destroying their pool, so make delete
-     inaccessible too.  */
-  void operator delete (void *) {}
 };
 
 /* Report whether P is a contitional branching instruction.  */
@@ -582,8 +567,6 @@ public:
   /* Default destructor.  */
   ~hsa_insn_sbr ();
 
-  void *operator new (size_t);
-
   void replace_all_labels (basic_block old_bb, basic_block new_bb);
 
   /* Width as described in HSA documentation.  */
@@ -598,9 +581,6 @@ public:
 private:
   /* Make the default constructor inaccessible.  */
   hsa_insn_sbr () : hsa_insn_basic (1, BRIG_OPCODE_SBR) {}
-  /* All objects are deallocated by destroying their pool, so make delete
-     inaccessible too.  */
-  void operator delete (void *) {}
 };
 
 /* Report whether P is a switch branching instruction.  */
@@ -622,8 +602,6 @@ public:
 		hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
 		hsa_op_base *arg2 = NULL);
 
-  void *operator new (size_t);
-
   /* Source type should be derived from operand types.  */
 
   /* The comparison operation.  */
@@ -634,9 +612,6 @@ public:
 private:
   /* Make the default constructor inaccessible.  */
   hsa_insn_cmp () : hsa_insn_basic (1, BRIG_OPCODE_CMP) {}
-  /* All objects are deallocated by destroying their pool, so make delete
-     inaccessible too.  */
-  void operator delete (void *) {}
 };
 
 /* Report whether or not P is a comparison instruction.  */
@@ -656,8 +631,6 @@ class hsa_insn_mem : public hsa_insn_basic
 public:
   hsa_insn_mem (int opc, BrigType16_t t, hsa_op_base *arg0, hsa_op_base *arg1);
 
-  void *operator new (size_t);
-
   /* Set alignment to VALUE.  */
 
   void set_align (BrigAlignment8_t value);
@@ -680,9 +653,6 @@ protected:
 private:
   /* Make the default constructor inaccessible.  */
   hsa_insn_mem () : hsa_insn_basic (1, BRIG_OPCODE_LD) {}
-  /* All objects are deallocated by destroying their pool, so make delete
-     inaccessible too.  */
-  void operator delete (void *) {}
 };
 
 /* Report whether or not P is a memory instruction.  */
@@ -705,7 +675,6 @@ public:
 		   BrigType16_t t, BrigMemoryOrder memorder,
 		   hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
 		   hsa_op_base *arg2 = NULL, hsa_op_base *arg3 = NULL);
-  void *operator new (size_t);
 
   /* The operation itself.  */
   enum BrigAtomicOperation m_atomicop;
@@ -719,9 +688,6 @@ public:
 private:
   /* Make the default constructor inaccessible.  */
   hsa_insn_atomic () : hsa_insn_mem (1, BRIG_KIND_NONE, BRIG_TYPE_NONE) {}
-  /* All objects are deallocated by destroying their pool, so make delete
-     inaccessible too.  */
-  void operator delete (void *) {}
 };
 
 /* Report whether or not P is an atomic instruction.  */
@@ -745,17 +711,11 @@ public:
 		   hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
 		   hsa_op_base *arg2 = NULL, hsa_op_base *arg3 = NULL);
 
-  void *operator new (size_t);
-
   /* Things like acquire/release/aligned.  */
   enum BrigMemoryOrder m_memory_order;
 
   /* The operation itself.  */
   enum BrigAtomicOperation m_signalop;
-private:
-  /* All objects are deallocated by destroying their pool, so make delete
-     inaccessible too.  */
-  void operator delete (void *) {}
 };
 
 /* Report whether or not P is a signal instruction.  */
@@ -777,8 +737,6 @@ public:
   hsa_insn_seg (int opc, BrigType16_t destt, BrigType16_t srct,
 		BrigSegment8_t seg, hsa_op_base *arg0, hsa_op_base *arg1);
 
-  void *operator new (size_t);
-
   /* Source type.  Depends on the source addressing/segment.  */
   BrigType16_t m_src_type;
   /* The segment we are converting from or to.  */
@@ -786,9 +744,6 @@ public:
 private:
   /* Make the default constructor inaccessible.  */
   hsa_insn_seg () : hsa_insn_basic (1, BRIG_OPCODE_STOF) {}
-  /* All objects are deallocated by destroying their pool, so make delete
-     inaccessible too.  */
-  void operator delete (void *) {}
 };
 
 /* Report whether or not P is a segment conversion instruction.  */
@@ -845,8 +800,6 @@ public:
   /* Default destructor.  */
   ~hsa_insn_call ();
 
-  void *operator new (size_t);
-
   /* Called function.  */
   tree m_called_function;
 
@@ -873,9 +826,6 @@ public:
 private:
   /* Make the default constructor inaccessible.  */
   hsa_insn_call () : hsa_insn_basic (0, BRIG_OPCODE_CALL) {}
-  /* All objects are deallocated by destroying their pool, so make delete
-     inaccessible too.  */
-  void operator delete (void *) {}
 };
 
 /* Report whether or not P is a call instruction.  */
@@ -899,17 +849,11 @@ class hsa_insn_arg_block : public hsa_insn_basic
 public:
   hsa_insn_arg_block (BrigKind brig_kind, hsa_insn_call * call);
 
-  void *operator new (size_t);
-
   /* Kind of argument block.  */
   BrigKind m_kind;
 
   /* Call instruction.  */
   hsa_insn_call *m_call_insn;
-private:
-  /* All objects are deallocated by destroying their pool, so make delete
-     inaccessible too.  */
-  void operator delete (void *) {}
 };
 
 /* Report whether or not P is a call block instruction.  */
@@ -933,8 +877,6 @@ public:
   /* Default destructor.  */
   ~hsa_insn_comment ();
 
-  void *operator new (size_t);
-
   char *m_comment;
 };
 
@@ -991,9 +933,6 @@ public:
 		   BrigType16_t srct, hsa_op_base *arg0, hsa_op_base *arg1,
 		   hsa_op_base *arg2);
 
-  /* Pool allocator.  */
-  void *operator new (size_t);
-
   /* Source type.  */
   BrigType16_t m_source_type;
 
@@ -1022,9 +961,6 @@ public:
 		   BrigType16_t srct, hsa_op_base *arg0, hsa_op_base *arg1,
 		   hsa_op_base *arg2);
 
-  /* Pool allocator.  */
-  void *operator new (size_t);
-
   /* Operand list for an operand of the instruction.  */
   hsa_op_operand_list *m_operand_list;
 
@@ -1049,9 +985,6 @@ class hsa_insn_cvt: public hsa_insn_basic
 {
 public:
   hsa_insn_cvt (hsa_op_with_type *dest, hsa_op_with_type *src);
-
-  /* Pool allocator.  */
-  void *operator new (size_t);
 };
 
 /* Report whether or not P is a convert instruction.  */
@@ -1074,9 +1007,6 @@ public:
 
   /* Required alignment of the allocation.  */
   BrigAlignment8_t m_align;
-
-  /* Pool allocator.  */
-  void *operator new (size_t);
 };
 
 /* Report whether or not P is an alloca instruction.  */
-- 
2.9.2



More information about the Gcc-patches mailing list