public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 5/9] ubsan.c: switch from POINTER_SIZE to targetm.pointer_size ()
  2015-07-27  3:10 [PATCH 0/9] start converting POINTER_SIZE to a hook tbsaunde+gcc
                   ` (5 preceding siblings ...)
  2015-07-27  3:10 ` [PATCH 1/9] remove POINTER_SIZE_UNITS macro tbsaunde+gcc
@ 2015-07-27  3:10 ` tbsaunde+gcc
  2015-07-27  3:42 ` [PATCH 6/9] tree-chkp.c: switch " tbsaunde+gcc
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 25+ messages in thread
From: tbsaunde+gcc @ 2015-07-27  3:10 UTC (permalink / raw)
  To: gcc-patches

From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

gcc/ChangeLog:

2015-07-26  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* ubsan.c (ubsan_encode_value): Call targetm.pointer_size ().
---
 gcc/ubsan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/ubsan.c b/gcc/ubsan.c
index d75c4ee..55d9440 100644
--- a/gcc/ubsan.c
+++ b/gcc/ubsan.c
@@ -63,6 +63,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-object-size.h"
 #include "tree-eh.h"
 #include "tree-cfg.h"
+#include "target.h"
 
 /* Map from a tree to a VAR_DECL tree.  */
 
@@ -139,7 +140,7 @@ ubsan_encode_value (tree t, bool in_expand_p)
 {
   tree type = TREE_TYPE (t);
   const unsigned int bitsize = GET_MODE_BITSIZE (TYPE_MODE (type));
-  if (bitsize <= POINTER_SIZE)
+  if (bitsize <= targetm.pointer_size ())
     switch (TREE_CODE (type))
       {
       case BOOLEAN_TYPE:
-- 
2.4.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 4/9] varasm.c: switch from POINTER_SIZE to targetm.pointer_size ()
  2015-07-27  3:10 [PATCH 0/9] start converting POINTER_SIZE to a hook tbsaunde+gcc
                   ` (3 preceding siblings ...)
  2015-07-27  3:10 ` [PATCH 3/9] target.h: change to use targetm.pointer_size instead of POINTER_SIZE tbsaunde+gcc
@ 2015-07-27  3:10 ` tbsaunde+gcc
  2015-07-27  9:32   ` Richard Biener
  2015-07-27  3:10 ` [PATCH 1/9] remove POINTER_SIZE_UNITS macro tbsaunde+gcc
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: tbsaunde+gcc @ 2015-07-27  3:10 UTC (permalink / raw)
  To: gcc-patches

From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

gcc/ChangeLog:

2015-07-26  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* varasm.c (assemble_addr_to_section): Call targetm.pointer_size ().
	(dump_tm_clone_pairs): Likewise.
---
 gcc/varasm.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/varasm.c b/gcc/varasm.c
index 8cb2ec9..238ae39 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -1543,8 +1543,8 @@ void
 assemble_addr_to_section (rtx symbol, section *sec)
 {
   switch_to_section (sec);
-  assemble_align (POINTER_SIZE);
-  assemble_integer (symbol, pointer_size_units (), POINTER_SIZE, 1);
+  assemble_align (targetm.pointer_size ());
+  assemble_integer (symbol, pointer_size_units (), targetm.pointer_size (), 1);
 }
 
 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
@@ -5870,14 +5870,14 @@ dump_tm_clone_pairs (vec<tm_alias_pair> tm_alias_pairs)
       if (!switched)
 	{
 	  switch_to_section (targetm.asm_out.tm_clone_table_section ());
-	  assemble_align (POINTER_SIZE);
+	  assemble_align (targetm.pointer_size ());
 	  switched = true;
 	}
 
       assemble_integer (XEXP (DECL_RTL (src), 0),
-			pointer_size_units (), POINTER_SIZE, 1);
+			pointer_size_units (), targetm.pointer_size (), 1);
       assemble_integer (XEXP (DECL_RTL (dst), 0),
-			pointer_size_units (), POINTER_SIZE, 1);
+			pointer_size_units (), targetm.pointer_size (), 1);
     }
 }
 
-- 
2.4.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 9/9] emit-rtl.c: switch to targetm.pointer_size ()
  2015-07-27  3:10 [PATCH 0/9] start converting POINTER_SIZE to a hook tbsaunde+gcc
@ 2015-07-27  3:10 ` tbsaunde+gcc
  2015-07-27  3:10 ` [PATCH 2/9] add pointer_size target hook tbsaunde+gcc
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 25+ messages in thread
From: tbsaunde+gcc @ 2015-07-27  3:10 UTC (permalink / raw)
  To: gcc-patches

From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

gcc/ChangeLog:

2015-07-26  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* emit-rtl.c (init_derived_machine_modes): Call
	targetm.pointer_size ().
---
 gcc/emit-rtl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index ed2b30b..9da93d1 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -76,7 +76,7 @@ struct target_rtl *this_target_rtl = &default_target_rtl;
 machine_mode byte_mode;	/* Mode whose width is BITS_PER_UNIT.  */
 machine_mode word_mode;	/* Mode whose width is BITS_PER_WORD.  */
 machine_mode double_mode;	/* Mode whose width is DOUBLE_TYPE_SIZE.  */
-machine_mode ptr_mode;	/* Mode whose width is POINTER_SIZE.  */
+machine_mode ptr_mode;	/* Mode whose width is targetm.pointer_size ().  */
 
 /* Datastructures maintained for currently processed function in RTL form.  */
 
@@ -5864,7 +5864,8 @@ init_derived_machine_modes (void)
 	word_mode = mode;
     }
 
-  ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
+  ptr_mode = mode_for_size (targetm.pointer_size (), GET_MODE_CLASS (Pmode),
+			    0);
 }
 
 /* Create some permanent unique rtl objects shared between all functions.  */
-- 
2.4.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 7/9] stor-layout.c: switch to targetm.pointer_size ()
  2015-07-27  3:10 [PATCH 0/9] start converting POINTER_SIZE to a hook tbsaunde+gcc
  2015-07-27  3:10 ` [PATCH 9/9] emit-rtl.c: switch to targetm.pointer_size () tbsaunde+gcc
  2015-07-27  3:10 ` [PATCH 2/9] add pointer_size target hook tbsaunde+gcc
@ 2015-07-27  3:10 ` tbsaunde+gcc
  2015-07-27  3:10 ` [PATCH 3/9] target.h: change to use targetm.pointer_size instead of POINTER_SIZE tbsaunde+gcc
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 25+ messages in thread
From: tbsaunde+gcc @ 2015-07-27  3:10 UTC (permalink / raw)
  To: gcc-patches

From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

gcc/ChangeLog:

2015-07-26  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* stor-layout.c (layout_type): Call targetm.pointer_size ().
---
 gcc/stor-layout.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 160ffe2..6043398 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -2228,12 +2228,13 @@ layout_type (tree type)
       break;
 
     case OFFSET_TYPE:
-      TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
+      TYPE_SIZE (type) = bitsize_int (targetm.pointer_size ());
       TYPE_SIZE_UNIT (type) = size_int (pointer_size_units ());
       /* A pointer might be MODE_PARTIAL_INT, but ptrdiff_t must be
 	 integral, which may be an __intN.  */
-      SET_TYPE_MODE (type, mode_for_size (POINTER_SIZE, MODE_INT, 0));
-      TYPE_PRECISION (type) = POINTER_SIZE;
+      SET_TYPE_MODE (type, mode_for_size (targetm.pointer_size (), MODE_INT,
+					  0));
+      TYPE_PRECISION (type) = targetm.pointer_size ();
       break;
 
     case FUNCTION_TYPE:
-- 
2.4.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 0/9] start converting POINTER_SIZE to a hook
@ 2015-07-27  3:10 tbsaunde+gcc
  2015-07-27  3:10 ` [PATCH 9/9] emit-rtl.c: switch to targetm.pointer_size () tbsaunde+gcc
                   ` (10 more replies)
  0 siblings, 11 replies; 25+ messages in thread
From: tbsaunde+gcc @ 2015-07-27  3:10 UTC (permalink / raw)
  To: gcc-patches

From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

Hi,

$subject.

patches individually bootstrapped + regtested on x86_64-linux-gnu, and run
through config-list.mk with more patches removing usage of the macro.  Ok?

Trev

Trevor Saunders (9):
  remove POINTER_SIZE_UNITS macro
  add pointer_size target hook
  target.h: change to use targetm.pointer_size instead of POINTER_SIZE
  varasm.c: switch from POINTER_SIZE to targetm.pointer_size ()
  ubsan.c: switch from POINTER_SIZE to targetm.pointer_size ()
  tree-chkp.c: switch to targetm.pointer_size ()
  stor-layout.c: switch to targetm.pointer_size ()
  tree.c: switch to targetm.pointer_size ()
  emit-rtl.c: switch to targetm.pointer_size ()

 gcc/c-family/c-cppbuiltin.c |  2 +-
 gcc/defaults.h              |  3 ---
 gcc/doc/tm.texi             |  7 +++++++
 gcc/doc/tm.texi.in          |  2 ++
 gcc/dwarf2asm.c             |  4 ++--
 gcc/emit-rtl.c              |  5 +++--
 gcc/lto/lto-object.c        |  3 ++-
 gcc/stor-layout.c           |  9 +++++----
 gcc/target.def              |  8 ++++++++
 gcc/target.h                |  8 ++++++++
 gcc/targhooks.c             |  8 ++++++++
 gcc/targhooks.h             |  1 +
 gcc/tree-chkp.c             | 14 ++++++++------
 gcc/tree.c                  |  3 ++-
 gcc/ubsan.c                 |  3 ++-
 gcc/varasm.c                | 12 ++++++------
 16 files changed, 65 insertions(+), 27 deletions(-)

-- 
2.4.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 1/9] remove POINTER_SIZE_UNITS macro
  2015-07-27  3:10 [PATCH 0/9] start converting POINTER_SIZE to a hook tbsaunde+gcc
                   ` (4 preceding siblings ...)
  2015-07-27  3:10 ` [PATCH 4/9] varasm.c: switch from POINTER_SIZE to targetm.pointer_size () tbsaunde+gcc
@ 2015-07-27  3:10 ` tbsaunde+gcc
  2015-07-27  3:10 ` [PATCH 5/9] ubsan.c: switch from POINTER_SIZE to targetm.pointer_size () tbsaunde+gcc
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 25+ messages in thread
From: tbsaunde+gcc @ 2015-07-27  3:10 UTC (permalink / raw)
  To: gcc-patches

From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

gcc/lto/ChangeLog:

2015-07-26  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* lto-object.c (lto_obj_begin_section): Call pointer_size_units ().

gcc/c-family/ChangeLog:

2015-07-26  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* c-cppbuiltin.c (cpp_atomic_builtins): Call pointer_size_units ().

gcc/ChangeLog:

2015-07-26  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* defaults.h (POINTER_SIZE_UNITS): Remove.
	* dwarf2asm.c (size_of_encoded_value): Adjust.
	(dw2_output_indirect_constant_1): Likewise.
	* stor-layout.c (layout_type): Likewise.
	* target.h (pointer_size_units): New function.
	* varasm.c (assemble_addr_to_section): Adjust.
	(default_assemble_integer): Likewise.
	(dump_tm_clone_pairs): Likewise.
---
 gcc/c-family/c-cppbuiltin.c | 2 +-
 gcc/defaults.h              | 3 ---
 gcc/dwarf2asm.c             | 4 ++--
 gcc/lto/lto-object.c        | 3 ++-
 gcc/stor-layout.c           | 2 +-
 gcc/target.h                | 8 ++++++++
 gcc/varasm.c                | 8 ++++----
 7 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index 1beb2db..73ec8eb 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -674,7 +674,7 @@ cpp_atomic_builtins (cpp_reader *pfile)
 
   /* ptr_type_node can't be used here since ptr_mode is only set when
      toplev calls backend_init which is not done with -E  or pch.  */
-  psize = POINTER_SIZE_UNITS;
+  psize = pointer_size_units ();
   if (psize >= SWAP_LIMIT)
     psize = 0;
   builtin_define_with_int_value ("__GCC_ATOMIC_POINTER_LOCK_FREE", 
diff --git a/gcc/defaults.h b/gcc/defaults.h
index 9d38ba1..1dd965b 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -771,9 +771,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #ifndef POINTER_SIZE
 #define POINTER_SIZE BITS_PER_WORD
 #endif
-#ifndef POINTER_SIZE_UNITS
-#define POINTER_SIZE_UNITS ((POINTER_SIZE + BITS_PER_UNIT - 1) / BITS_PER_UNIT)
-#endif
 
 
 #ifndef PIC_OFFSET_TABLE_REGNUM
diff --git a/gcc/dwarf2asm.c b/gcc/dwarf2asm.c
index 9f3c4b1..b63f82e 100644
--- a/gcc/dwarf2asm.c
+++ b/gcc/dwarf2asm.c
@@ -385,7 +385,7 @@ size_of_encoded_value (int encoding)
   switch (encoding & 0x07)
     {
     case DW_EH_PE_absptr:
-      return POINTER_SIZE_UNITS;
+      return pointer_size_units ();
     case DW_EH_PE_udata2:
       return 2;
     case DW_EH_PE_udata4:
@@ -902,7 +902,7 @@ dw2_output_indirect_constant_1 (const char *sym, tree id)
 
   sym_ref = gen_rtx_SYMBOL_REF (Pmode, sym);
   assemble_variable (decl, 1, 1, 1);
-  assemble_integer (sym_ref, POINTER_SIZE_UNITS, POINTER_SIZE, 1);
+  assemble_integer (sym_ref, pointer_size_units (), POINTER_SIZE, 1);
 
   return 0;
 }
diff --git a/gcc/lto/lto-object.c b/gcc/lto/lto-object.c
index 087c6b1..198a585 100644
--- a/gcc/lto/lto-object.c
+++ b/gcc/lto/lto-object.c
@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cgraph.h"
 #include "lto-section-names.h"
 #include "simple-object.h"
+#include "target.h"
 
 /* An LTO file wrapped around an simple_object.  */
 
@@ -340,7 +341,7 @@ lto_obj_begin_section (const char *name)
 	      && lo->sobj_w != NULL
 	      && lo->section == NULL);
 
-  align = ceil_log2 (POINTER_SIZE_UNITS);
+  align = ceil_log2 (pointer_size_units ());
   lo->section = simple_object_write_create_section (lo->sobj_w, name, align,
 						    &errmsg, &err);
   if (lo->section == NULL)
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 0d4f4a4..160ffe2 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -2229,7 +2229,7 @@ layout_type (tree type)
 
     case OFFSET_TYPE:
       TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
-      TYPE_SIZE_UNIT (type) = size_int (POINTER_SIZE_UNITS);
+      TYPE_SIZE_UNIT (type) = size_int (pointer_size_units ());
       /* A pointer might be MODE_PARTIAL_INT, but ptrdiff_t must be
 	 integral, which may be an __intN.  */
       SET_TYPE_MODE (type, mode_for_size (POINTER_SIZE, MODE_INT, 0));
diff --git a/gcc/target.h b/gcc/target.h
index a79f424..6715b07 100644
--- a/gcc/target.h
+++ b/gcc/target.h
@@ -219,4 +219,12 @@ pack_cumulative_args (CUMULATIVE_ARGS *arg)
 }
 #endif /* GCC_TM_H */
 
+/* Return the width of a pointer in units.  */
+
+inline unsigned int
+pointer_size_units ()
+{
+  return (POINTER_SIZE + BITS_PER_UNIT - 1) /  BITS_PER_UNIT;
+}
+
 #endif /* GCC_TARGET_H */
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 6a4ba0b..8cb2ec9 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -1544,7 +1544,7 @@ assemble_addr_to_section (rtx symbol, section *sec)
 {
   switch_to_section (sec);
   assemble_align (POINTER_SIZE);
-  assemble_integer (symbol, POINTER_SIZE_UNITS, POINTER_SIZE, 1);
+  assemble_integer (symbol, pointer_size_units (), POINTER_SIZE, 1);
 }
 
 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
@@ -2732,7 +2732,7 @@ default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
   const char *op = integer_asm_op (size, aligned_p);
   /* Avoid GAS bugs for large values.  Specifically negative values whose
      absolute value fits in a bfd_vma, but not in a bfd_signed_vma.  */
-  if (size > UNITS_PER_WORD && size > POINTER_SIZE_UNITS)
+  if (size > UNITS_PER_WORD && size > pointer_size_units ())
     return false;
   return op && (assemble_integer_with_op (op, x), true);
 }
@@ -5875,9 +5875,9 @@ dump_tm_clone_pairs (vec<tm_alias_pair> tm_alias_pairs)
 	}
 
       assemble_integer (XEXP (DECL_RTL (src), 0),
-			POINTER_SIZE_UNITS, POINTER_SIZE, 1);
+			pointer_size_units (), POINTER_SIZE, 1);
       assemble_integer (XEXP (DECL_RTL (dst), 0),
-			POINTER_SIZE_UNITS, POINTER_SIZE, 1);
+			pointer_size_units (), POINTER_SIZE, 1);
     }
 }
 
-- 
2.4.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 3/9] target.h: change to use targetm.pointer_size instead of POINTER_SIZE
  2015-07-27  3:10 [PATCH 0/9] start converting POINTER_SIZE to a hook tbsaunde+gcc
                   ` (2 preceding siblings ...)
  2015-07-27  3:10 ` [PATCH 7/9] stor-layout.c: switch to targetm.pointer_size () tbsaunde+gcc
@ 2015-07-27  3:10 ` tbsaunde+gcc
  2015-07-27  3:10 ` [PATCH 4/9] varasm.c: switch from POINTER_SIZE to targetm.pointer_size () tbsaunde+gcc
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 25+ messages in thread
From: tbsaunde+gcc @ 2015-07-27  3:10 UTC (permalink / raw)
  To: gcc-patches

From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

gcc/ChangeLog:

2015-07-26  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* target.h (pointer_size_units): Call targetm.pointer_size ().
---
 gcc/target.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/target.h b/gcc/target.h
index 6715b07..435bc7e 100644
--- a/gcc/target.h
+++ b/gcc/target.h
@@ -224,7 +224,7 @@ pack_cumulative_args (CUMULATIVE_ARGS *arg)
 inline unsigned int
 pointer_size_units ()
 {
-  return (POINTER_SIZE + BITS_PER_UNIT - 1) /  BITS_PER_UNIT;
+  return (targetm.pointer_size () + BITS_PER_UNIT - 1) /  BITS_PER_UNIT;
 }
 
 #endif /* GCC_TARGET_H */
-- 
2.4.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 2/9] add pointer_size target hook
  2015-07-27  3:10 [PATCH 0/9] start converting POINTER_SIZE to a hook tbsaunde+gcc
  2015-07-27  3:10 ` [PATCH 9/9] emit-rtl.c: switch to targetm.pointer_size () tbsaunde+gcc
@ 2015-07-27  3:10 ` tbsaunde+gcc
  2015-07-27  3:10 ` [PATCH 7/9] stor-layout.c: switch to targetm.pointer_size () tbsaunde+gcc
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 25+ messages in thread
From: tbsaunde+gcc @ 2015-07-27  3:10 UTC (permalink / raw)
  To: gcc-patches

From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

gcc/ChangeLog:

2015-07-26  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* doc/tm.texi: Regenerate.
	* doc/tm.texi.in: Adjust.
	* target.def (pointer_size): New hook.
	* targhooks.c (default_pointer_size): New function.
	* targhooks.h (default_pointer_size): New function.
---
 gcc/doc/tm.texi    | 7 +++++++
 gcc/doc/tm.texi.in | 2 ++
 gcc/target.def     | 8 ++++++++
 gcc/targhooks.c    | 8 ++++++++
 gcc/targhooks.h    | 1 +
 5 files changed, 26 insertions(+)

diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index f95646c..34cc8f6 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -907,6 +907,13 @@ you must define @code{POINTERS_EXTEND_UNSIGNED}.  If you do not specify
 a value the default is @code{BITS_PER_WORD}.
 @end defmac
 
+@deftypefn {Target Hook} {unsigned int} TARGET_POINTER_SIZE ()
+Width of a pointer, in bits.  You must specify a value no wider than the
+ width of @code{Pmode}.  If it is not equal to the width of @code{Pmode},
+ you must define @code{POINTERS_EXTEND_UNSIGNED}.  If you do not specify
+ a value the default is @code{BITS_PER_WORD}.
+@end deftypefn
+
 @defmac POINTERS_EXTEND_UNSIGNED
 A C expression that determines how pointers should be extended from
 @code{ptr_mode} to either @code{Pmode} or @code{word_mode}.  It is
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 2383fb9..ca08f11 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -881,6 +881,8 @@ you must define @code{POINTERS_EXTEND_UNSIGNED}.  If you do not specify
 a value the default is @code{BITS_PER_WORD}.
 @end defmac
 
+@hook TARGET_POINTER_SIZE
+
 @defmac POINTERS_EXTEND_UNSIGNED
 A C expression that determines how pointers should be extended from
 @code{ptr_mode} to either @code{Pmode} or @code{word_mode}.  It is
diff --git a/gcc/target.def b/gcc/target.def
index 4edc209..2e247e0 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -5716,6 +5716,14 @@ DEFHOOK
  void, (tree *hold, tree *clear, tree *update),
  default_atomic_assign_expand_fenv)
 
+DEFHOOK
+(pointer_size,
+"Width of a pointer, in bits.  You must specify a value no wider than the\n\
+ width of @code{Pmode}.  If it is not equal to the width of @code{Pmode},\n\
+ you must define @code{POINTERS_EXTEND_UNSIGNED}.  If you do not specify\n\
+ a value the default is @code{BITS_PER_WORD}.",
+unsigned int, (), default_pointer_size)
+
 /* Leave the boolean fields at the end.  */
 
 /* True if we can create zeroed data by switching to a BSS section
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index 3eca47e..19272c4 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -1926,4 +1926,12 @@ can_use_doloop_if_innermost (const widest_int &, const widest_int &,
   return loop_depth == 1;
 }
 
+/* Default implementation of TARGET_POINTER_SIZE.  */
+
+unsigned int
+default_pointer_size ()
+{
+  return POINTER_SIZE;
+}
+
 #include "gt-targhooks.h"
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index 5ae991d..6782d37 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -240,4 +240,5 @@ extern void default_setup_incoming_vararg_bounds (cumulative_args_t ca ATTRIBUTE
 						  tree type ATTRIBUTE_UNUSED,
 						  int *pretend_arg_size ATTRIBUTE_UNUSED,
 						  int second_time ATTRIBUTE_UNUSED);
+extern unsigned int default_pointer_size ();
 #endif /* GCC_TARGHOOKS_H */
-- 
2.4.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 6/9] tree-chkp.c: switch to targetm.pointer_size ()
  2015-07-27  3:10 [PATCH 0/9] start converting POINTER_SIZE to a hook tbsaunde+gcc
                   ` (6 preceding siblings ...)
  2015-07-27  3:10 ` [PATCH 5/9] ubsan.c: switch from POINTER_SIZE to targetm.pointer_size () tbsaunde+gcc
@ 2015-07-27  3:42 ` tbsaunde+gcc
  2015-07-27  3:49 ` [PATCH 8/9] tree.c: " tbsaunde+gcc
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 25+ messages in thread
From: tbsaunde+gcc @ 2015-07-27  3:42 UTC (permalink / raw)
  To: gcc-patches

From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

gcc/ChangeLog:

2015-07-26  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* tree-chkp.c (chkp_build_array_ref): Call targetm.pointer_size ().
	(chkp_find_bounds_for_elem): Likewise.
	(chkp_find_bound_slots_1): Likewise.
	(chkp_add_bounds_to_call_stmt): Likewise.
	(chkp_instrument_function): Likewise.
---
 gcc/tree-chkp.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 8c1b48c..456e79b 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -1583,7 +1583,7 @@ chkp_build_array_ref (tree arr, tree etype, tree esize,
 
    ALL_BOUNDS[i] is filled with elem bounds if there
    is a field in TYPE which has pointer type and offset
-   equal to i * POINTER_SIZE in bits.  */
+   equal to i * targetm.pointer_size () in bits.  */
 static void
 chkp_find_bounds_for_elem (tree elem, tree *all_bounds,
 			   HOST_WIDE_INT offs,
@@ -1593,7 +1593,7 @@ chkp_find_bounds_for_elem (tree elem, tree *all_bounds,
 
   if (BOUNDED_TYPE_P (type))
     {
-      if (!all_bounds[offs / POINTER_SIZE])
+      if (!all_bounds[offs / targetm.pointer_size ()])
 	{
 	  tree temp = make_temp_ssa_name (type, NULL, "");
 	  gimple assign = gimple_build_assign (temp, elem);
@@ -1602,7 +1602,8 @@ chkp_find_bounds_for_elem (tree elem, tree *all_bounds,
 	  gsi_insert_before (iter, assign, GSI_SAME_STMT);
 	  gsi = gsi_for_stmt (assign);
 
-	  all_bounds[offs / POINTER_SIZE] = chkp_find_bounds (temp, &gsi);
+	  all_bounds[offs / targetm.pointer_size ()]
+	    = chkp_find_bounds (temp, &gsi);
 	}
     }
   else if (RECORD_OR_UNION_TYPE_P (type))
@@ -1659,7 +1660,7 @@ chkp_find_bound_slots_1 (const_tree type, bitmap have_bound,
 			 HOST_WIDE_INT offs)
 {
   if (BOUNDED_TYPE_P (type))
-    bitmap_set_bit (have_bound, offs / POINTER_SIZE);
+    bitmap_set_bit (have_bound, offs / targetm.pointer_size ());
   else if (RECORD_OR_UNION_TYPE_P (type))
     {
       tree field;
@@ -1906,7 +1907,7 @@ chkp_add_bounds_to_call_stmt (gimple_stmt_iterator *gsi)
       else if (chkp_type_has_pointer (type))
 	{
 	  HOST_WIDE_INT max_bounds
-	    = TREE_INT_CST_LOW (TYPE_SIZE (type)) / POINTER_SIZE;
+	    = TREE_INT_CST_LOW (TYPE_SIZE (type)) / targetm.pointer_size ();
 	  tree *all_bounds = (tree *)xmalloc (sizeof (tree) * max_bounds);
 	  HOST_WIDE_INT bnd_no;
 
@@ -4267,7 +4268,8 @@ chkp_instrument_function (void)
 	      EXECUTE_IF_SET_IN_BITMAP (slots, 0, bnd_no, bi)
 		{
 		  tree bounds = chkp_get_next_bounds_parm (arg);
-		  HOST_WIDE_INT offs = bnd_no * POINTER_SIZE / BITS_PER_UNIT;
+		  HOST_WIDE_INT offs
+		    = bnd_no * targetm.pointer_size () / BITS_PER_UNIT;
 		  tree addr = chkp_build_addr_expr (orig_arg);
 		  tree ptr = build2 (MEM_REF, ptr_type_node, addr,
 				     build_int_cst (ptr_type_node, offs));
-- 
2.4.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 8/9] tree.c: switch to targetm.pointer_size ()
  2015-07-27  3:10 [PATCH 0/9] start converting POINTER_SIZE to a hook tbsaunde+gcc
                   ` (7 preceding siblings ...)
  2015-07-27  3:42 ` [PATCH 6/9] tree-chkp.c: switch " tbsaunde+gcc
@ 2015-07-27  3:49 ` tbsaunde+gcc
  2015-07-27  9:26 ` [PATCH 0/9] start converting POINTER_SIZE to a hook Richard Biener
  2015-07-29 10:40 ` Richard Earnshaw
  10 siblings, 0 replies; 25+ messages in thread
From: tbsaunde+gcc @ 2015-07-27  3:49 UTC (permalink / raw)
  To: gcc-patches

From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

gcc/ChangeLog:

2015-07-26  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* tree.c (build_common_tree_nodes): Call targetm.pointer_size ().
---
 gcc/tree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/tree.c b/gcc/tree.c
index 94263af..02cbda8 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -9986,7 +9986,8 @@ build_common_tree_nodes (bool signed_char, bool short_double)
     = build_pointer_type (build_type_variant (void_type_node, 1, 0));
   fileptr_type_node = ptr_type_node;
 
-  pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
+  pointer_sized_int_node
+    = build_nonstandard_integer_type (targetm.pointer_size (), 1);
 
   float_type_node = make_node (REAL_TYPE);
   TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
-- 
2.4.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
  2015-07-27  3:10 [PATCH 0/9] start converting POINTER_SIZE to a hook tbsaunde+gcc
                   ` (8 preceding siblings ...)
  2015-07-27  3:49 ` [PATCH 8/9] tree.c: " tbsaunde+gcc
@ 2015-07-27  9:26 ` Richard Biener
  2015-07-27 16:20   ` Jeff Law
  2015-07-29 10:40 ` Richard Earnshaw
  10 siblings, 1 reply; 25+ messages in thread
From: Richard Biener @ 2015-07-27  9:26 UTC (permalink / raw)
  To: tbsaunde+gcc; +Cc: GCC Patches

On Mon, Jul 27, 2015 at 5:10 AM,  <tbsaunde+gcc@tbsaunde.org> wrote:
> From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
>
> Hi,
>
> $subject.
>
> patches individually bootstrapped + regtested on x86_64-linux-gnu, and run
> through config-list.mk with more patches removing usage of the macro.  Ok?

With POINTER_SIZE now being expensive (target hook) you might consider
moving most users to use pointer_sized_int_node or some other global
derived from POINTER_SIZE.

Which of course raises the question of why we are hookizing this...  if you'd
want a truly switchable target you'd have to switch all global trees as well
(or hookize them individually).

Richard.

> Trev
>
> Trevor Saunders (9):
>   remove POINTER_SIZE_UNITS macro
>   add pointer_size target hook
>   target.h: change to use targetm.pointer_size instead of POINTER_SIZE
>   varasm.c: switch from POINTER_SIZE to targetm.pointer_size ()
>   ubsan.c: switch from POINTER_SIZE to targetm.pointer_size ()
>   tree-chkp.c: switch to targetm.pointer_size ()
>   stor-layout.c: switch to targetm.pointer_size ()
>   tree.c: switch to targetm.pointer_size ()
>   emit-rtl.c: switch to targetm.pointer_size ()
>
>  gcc/c-family/c-cppbuiltin.c |  2 +-
>  gcc/defaults.h              |  3 ---
>  gcc/doc/tm.texi             |  7 +++++++
>  gcc/doc/tm.texi.in          |  2 ++
>  gcc/dwarf2asm.c             |  4 ++--
>  gcc/emit-rtl.c              |  5 +++--
>  gcc/lto/lto-object.c        |  3 ++-
>  gcc/stor-layout.c           |  9 +++++----
>  gcc/target.def              |  8 ++++++++
>  gcc/target.h                |  8 ++++++++
>  gcc/targhooks.c             |  8 ++++++++
>  gcc/targhooks.h             |  1 +
>  gcc/tree-chkp.c             | 14 ++++++++------
>  gcc/tree.c                  |  3 ++-
>  gcc/ubsan.c                 |  3 ++-
>  gcc/varasm.c                | 12 ++++++------
>  16 files changed, 65 insertions(+), 27 deletions(-)
>
> --
> 2.4.0
>

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 4/9] varasm.c: switch from POINTER_SIZE to targetm.pointer_size ()
  2015-07-27  3:10 ` [PATCH 4/9] varasm.c: switch from POINTER_SIZE to targetm.pointer_size () tbsaunde+gcc
@ 2015-07-27  9:32   ` Richard Biener
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Biener @ 2015-07-27  9:32 UTC (permalink / raw)
  To: tbsaunde+gcc; +Cc: GCC Patches

On Mon, Jul 27, 2015 at 5:10 AM,  <tbsaunde+gcc@tbsaunde.org> wrote:
> From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
>
> gcc/ChangeLog:
>
> 2015-07-26  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>
>
>         * varasm.c (assemble_addr_to_section): Call targetm.pointer_size ().
>         (dump_tm_clone_pairs): Likewise.
> ---
>  gcc/varasm.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/gcc/varasm.c b/gcc/varasm.c
> index 8cb2ec9..238ae39 100644
> --- a/gcc/varasm.c
> +++ b/gcc/varasm.c
> @@ -1543,8 +1543,8 @@ void
>  assemble_addr_to_section (rtx symbol, section *sec)
>  {
>    switch_to_section (sec);
> -  assemble_align (POINTER_SIZE);
> -  assemble_integer (symbol, pointer_size_units (), POINTER_SIZE, 1);
> +  assemble_align (targetm.pointer_size ());
> +  assemble_integer (symbol, pointer_size_units (), targetm.pointer_size (), 1);

That'll invoke the pointer size hook twice.  Refactoring assemble_integer to
avoid this would be nice.  Also caching the values in places like this.

Richard.

>  }
>
>  /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
> @@ -5870,14 +5870,14 @@ dump_tm_clone_pairs (vec<tm_alias_pair> tm_alias_pairs)
>        if (!switched)
>         {
>           switch_to_section (targetm.asm_out.tm_clone_table_section ());
> -         assemble_align (POINTER_SIZE);
> +         assemble_align (targetm.pointer_size ());
>           switched = true;
>         }
>
>        assemble_integer (XEXP (DECL_RTL (src), 0),
> -                       pointer_size_units (), POINTER_SIZE, 1);
> +                       pointer_size_units (), targetm.pointer_size (), 1);
>        assemble_integer (XEXP (DECL_RTL (dst), 0),
> -                       pointer_size_units (), POINTER_SIZE, 1);
> +                       pointer_size_units (), targetm.pointer_size (), 1);
>      }
>  }
>
> --
> 2.4.0
>

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
  2015-07-27  9:26 ` [PATCH 0/9] start converting POINTER_SIZE to a hook Richard Biener
@ 2015-07-27 16:20   ` Jeff Law
  2015-07-27 20:15     ` Richard Sandiford
  2015-07-28  3:47     ` Trevor Saunders
  0 siblings, 2 replies; 25+ messages in thread
From: Jeff Law @ 2015-07-27 16:20 UTC (permalink / raw)
  To: Richard Biener, tbsaunde+gcc; +Cc: GCC Patches

On 07/27/2015 03:17 AM, Richard Biener wrote:
> On Mon, Jul 27, 2015 at 5:10 AM,  <tbsaunde+gcc@tbsaunde.org> wrote:
>> From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
>>
>> Hi,
>>
>> $subject.
>>
>> patches individually bootstrapped + regtested on x86_64-linux-gnu, and run
>> through config-list.mk with more patches removing usage of the macro.  Ok?
>
> With POINTER_SIZE now being expensive (target hook) you might consider
> moving most users to use pointer_sized_int_node or some other global
> derived from POINTER_SIZE.
>
> Which of course raises the question of why we are hookizing this...  if you'd
> want a truly switchable target you'd have to switch all global trees as well
> (or hookize them individually).
Not sure -- it doesn't remove any conditionally compiled code...

One could easily argue that it's just another step on the path towards a 
switchable target -- which in and of itself is a reasonable design goal.

Trevor, maybe a quick note on the motivation would help here...

jeff



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
  2015-07-27 16:20   ` Jeff Law
@ 2015-07-27 20:15     ` Richard Sandiford
  2015-07-28  5:52       ` Trevor Saunders
  2015-07-28  3:47     ` Trevor Saunders
  1 sibling, 1 reply; 25+ messages in thread
From: Richard Sandiford @ 2015-07-27 20:15 UTC (permalink / raw)
  To: Jeff Law; +Cc: Richard Biener, tbsaunde+gcc, GCC Patches

Jeff Law <law@redhat.com> writes:
> On 07/27/2015 03:17 AM, Richard Biener wrote:
>> On Mon, Jul 27, 2015 at 5:10 AM,  <tbsaunde+gcc@tbsaunde.org> wrote:
>>> From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
>>>
>>> Hi,
>>>
>>> $subject.
>>>
>>> patches individually bootstrapped + regtested on x86_64-linux-gnu, and run
>>> through config-list.mk with more patches removing usage of the macro.  Ok?
>>
>> With POINTER_SIZE now being expensive (target hook) you might consider
>> moving most users to use pointer_sized_int_node or some other global
>> derived from POINTER_SIZE.
>>
>> Which of course raises the question of why we are hookizing this...  if you'd
>> want a truly switchable target you'd have to switch all global trees as well
>> (or hookize them individually).
> Not sure -- it doesn't remove any conditionally compiled code...
>
> One could easily argue that it's just another step on the path towards a 
> switchable target -- which in and of itself is a reasonable design goal.
>
> Trevor, maybe a quick note on the motivation would help here...

I think at least we should use data hooks rather than function hooks,
since this value should a constant within a subtarget.  It should only
change for target_reinit.

Alternatively we could have a new target_globals structure that is
initialised with the result of calling the hook.  If we do that though,
it might make sense to consolidate the hooks rather than have one for
every value.  E.g. having one function for UNITS_PER_WORD, one for
POINTER_SIZE, one for Pmode, etc., would lead to some very verbose
target code.

Perhaps the main problem with these approaches is ensuring that the
value is set up early enough.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
  2015-07-27 16:20   ` Jeff Law
  2015-07-27 20:15     ` Richard Sandiford
@ 2015-07-28  3:47     ` Trevor Saunders
  1 sibling, 0 replies; 25+ messages in thread
From: Trevor Saunders @ 2015-07-28  3:47 UTC (permalink / raw)
  To: Jeff Law; +Cc: Richard Biener, tbsaunde+gcc, GCC Patches

On Mon, Jul 27, 2015 at 10:14:41AM -0600, Jeff Law wrote:
> On 07/27/2015 03:17 AM, Richard Biener wrote:
> >On Mon, Jul 27, 2015 at 5:10 AM,  <tbsaunde+gcc@tbsaunde.org> wrote:
> >>From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
> >>
> >>Hi,
> >>
> >>$subject.
> >>
> >>patches individually bootstrapped + regtested on x86_64-linux-gnu, and run
> >>through config-list.mk with more patches removing usage of the macro.  Ok?
> >
> >With POINTER_SIZE now being expensive (target hook) you might consider
> >moving most users to use pointer_sized_int_node or some other global
> >derived from POINTER_SIZE.
> >
> >Which of course raises the question of why we are hookizing this...  if you'd
> >want a truly switchable target you'd have to switch all global trees as well
> >(or hookize them individually).
> Not sure -- it doesn't remove any conditionally compiled code...
> 
> One could easily argue that it's just another step on the path towards a
> switchable target -- which in and of itself is a reasonable design goal.

So my some what more intermediate goal was to have less files including
target specific headers, eventually getting to the point we might be
able to build a large part of the compiler independent of the
target.  Of course I think in the end really switchable targets would be
nice.

Trev

> 
> Trevor, maybe a quick note on the motivation would help here...
> 
> jeff
> 
> 
> 

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
  2015-07-27 20:15     ` Richard Sandiford
@ 2015-07-28  5:52       ` Trevor Saunders
  2015-07-28 20:36         ` Richard Sandiford
  0 siblings, 1 reply; 25+ messages in thread
From: Trevor Saunders @ 2015-07-28  5:52 UTC (permalink / raw)
  To: Jeff Law, Richard Biener, tbsaunde+gcc, GCC Patches, rdsandiford

On Mon, Jul 27, 2015 at 09:05:08PM +0100, Richard Sandiford wrote:
> Jeff Law <law@redhat.com> writes:
> > On 07/27/2015 03:17 AM, Richard Biener wrote:
> >> On Mon, Jul 27, 2015 at 5:10 AM,  <tbsaunde+gcc@tbsaunde.org> wrote:
> >>> From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
> >>>
> >>> Hi,
> >>>
> >>> $subject.
> >>>
> >>> patches individually bootstrapped + regtested on x86_64-linux-gnu, and run
> >>> through config-list.mk with more patches removing usage of the macro.  Ok?
> >>
> >> With POINTER_SIZE now being expensive (target hook) you might consider
> >> moving most users to use pointer_sized_int_node or some other global
> >> derived from POINTER_SIZE.
> >>
> >> Which of course raises the question of why we are hookizing this...  if you'd
> >> want a truly switchable target you'd have to switch all global trees as well
> >> (or hookize them individually).
> > Not sure -- it doesn't remove any conditionally compiled code...
> >
> > One could easily argue that it's just another step on the path towards a 
> > switchable target -- which in and of itself is a reasonable design goal.
> >
> > Trevor, maybe a quick note on the motivation would help here...
> 
> I think at least we should use data hooks rather than function hooks,
> since this value should a constant within a subtarget.  It should only
> change for target_reinit.

I agree in principal, but I wasn't sure where all I might need to change
the values of the hooks, and of course I wondered if there might be some
crazy target where that's not good enough.

> Alternatively we could have a new target_globals structure that is
> initialised with the result of calling the hook.  If we do that though,
> it might make sense to consolidate the hooks rather than have one for
> every value.  E.g. having one function for UNITS_PER_WORD, one for
> POINTER_SIZE, one for Pmode, etc., would lead to some very verbose
> target code.

so something like

struct target_types
{
  unsigned long pointer_size;
  ...
};

const target_types &targetm.get_type_data ()

? that seems pretty reasonable, and I wouldn't expect too many ordering
issues, but who knows.  Its too bad nobody has taken on the big job of
turning targetm into a class so we can hope for some devirt help from
the compiler.

thanks!

Trev

> 
> Perhaps the main problem with these approaches is ensuring that the
> value is set up early enough.
> 
> Thanks,
> Richard

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
  2015-07-28  5:52       ` Trevor Saunders
@ 2015-07-28 20:36         ` Richard Sandiford
  2015-07-29  4:44           ` Trevor Saunders
  0 siblings, 1 reply; 25+ messages in thread
From: Richard Sandiford @ 2015-07-28 20:36 UTC (permalink / raw)
  To: Trevor Saunders; +Cc: Jeff Law, Richard Biener, tbsaunde+gcc, GCC Patches

Trevor Saunders <tbsaunde@tbsaunde.org> writes:
> On Mon, Jul 27, 2015 at 09:05:08PM +0100, Richard Sandiford wrote:
>> Alternatively we could have a new target_globals structure that is
>> initialised with the result of calling the hook.  If we do that though,
>> it might make sense to consolidate the hooks rather than have one for
>> every value.  E.g. having one function for UNITS_PER_WORD, one for
>> POINTER_SIZE, one for Pmode, etc., would lead to some very verbose
>> target code.
>
> so something like
>
> struct target_types
> {
>   unsigned long pointer_size;
>   ...
> };
>
> const target_types &targetm.get_type_data ()
>
> ? that seems pretty reasonable, and I wouldn't expect too many ordering
> issues, but who knows.  Its too bad nobody has taken on the big job of
> turning targetm into a class so we can hope for some devirt help from
> the compiler.

I was thinking more:

  void targetm.get_type_data (target_types *);

The caller could then initialise or post-process the defaults.  The
target_types would eventually end up in some target_globals structure.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
  2015-07-28 20:36         ` Richard Sandiford
@ 2015-07-29  4:44           ` Trevor Saunders
  2015-07-29  8:32             ` Richard Sandiford
  0 siblings, 1 reply; 25+ messages in thread
From: Trevor Saunders @ 2015-07-29  4:44 UTC (permalink / raw)
  To: Jeff Law, Richard Biener, tbsaunde+gcc, GCC Patches, rdsandiford

On Tue, Jul 28, 2015 at 09:24:17PM +0100, Richard Sandiford wrote:
> Trevor Saunders <tbsaunde@tbsaunde.org> writes:
> > On Mon, Jul 27, 2015 at 09:05:08PM +0100, Richard Sandiford wrote:
> >> Alternatively we could have a new target_globals structure that is
> >> initialised with the result of calling the hook.  If we do that though,
> >> it might make sense to consolidate the hooks rather than have one for
> >> every value.  E.g. having one function for UNITS_PER_WORD, one for
> >> POINTER_SIZE, one for Pmode, etc., would lead to some very verbose
> >> target code.
> >
> > so something like
> >
> > struct target_types
> > {
> >   unsigned long pointer_size;
> >   ...
> > };
> >
> > const target_types &targetm.get_type_data ()
> >
> > ? that seems pretty reasonable, and I wouldn't expect too many ordering
> > issues, but who knows.  Its too bad nobody has taken on the big job of
> > turning targetm into a class so we can hope for some devirt help from
> > the compiler.
> 
> I was thinking more:
> 
>   void targetm.get_type_data (target_types *);
> 
> The caller could then initialise or post-process the defaults.  The
> target_types would eventually end up in some target_globals structure.

but wouldn't that mean the hook would need to initialize all the fields
every time the hook was called?  I'd think you'd want to avoid that
work, and have a global or set of global constant  target_types structs,
and based on the target in use you could return the appropriate one.  a
target could also just have global one, but change its values when the
sub target changes, but having it be constant seems like a nicer design
for the target.  I guess that has the disadvantage that if the target
isn't a switchable target you need to reinitialize the whole struct
every time the hook is called on the off chance something has changed,
but that seems like the same thing that happens in your proposal?

Trev

> 
> Thanks,
> Richard

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
  2015-07-29  4:44           ` Trevor Saunders
@ 2015-07-29  8:32             ` Richard Sandiford
  2015-07-30  8:13               ` Trevor Saunders
  0 siblings, 1 reply; 25+ messages in thread
From: Richard Sandiford @ 2015-07-29  8:32 UTC (permalink / raw)
  To: Trevor Saunders; +Cc: Jeff Law, Richard Biener, tbsaunde+gcc, GCC Patches

Trevor Saunders <tbsaunde@tbsaunde.org> writes:
> On Tue, Jul 28, 2015 at 09:24:17PM +0100, Richard Sandiford wrote:
>> Trevor Saunders <tbsaunde@tbsaunde.org> writes:
>> > On Mon, Jul 27, 2015 at 09:05:08PM +0100, Richard Sandiford wrote:
>> >> Alternatively we could have a new target_globals structure that is
>> >> initialised with the result of calling the hook.  If we do that though,
>> >> it might make sense to consolidate the hooks rather than have one for
>> >> every value.  E.g. having one function for UNITS_PER_WORD, one for
>> >> POINTER_SIZE, one for Pmode, etc., would lead to some very verbose
>> >> target code.
>> >
>> > so something like
>> >
>> > struct target_types
>> > {
>> >   unsigned long pointer_size;
>> >   ...
>> > };
>> >
>> > const target_types &targetm.get_type_data ()
>> >
>> > ? that seems pretty reasonable, and I wouldn't expect too many ordering
>> > issues, but who knows.  Its too bad nobody has taken on the big job of
>> > turning targetm into a class so we can hope for some devirt help from
>> > the compiler.
>> 
>> I was thinking more:
>> 
>>   void targetm.get_type_data (target_types *);
>> 
>> The caller could then initialise or post-process the defaults.  The
>> target_types would eventually end up in some target_globals structure.
>
> but wouldn't that mean the hook would need to initialize all the fields
> every time the hook was called?

Yeah, but the idea was that the hook would only be called once per
target initialisation and the result would be stored in a target_globals
structure.  Then places that use POINTER_SIZE would instead use the
cached target_globals structure rather than targetm.

For SWITCHABLE_TARGETs, the hook would be called only once for each
subtarget used by the TU.  For other targets it would be called
once for each change in subtarget (which is already very expensive without
SWITCHABLE_TARGET -- targets that want it to be fast should move to
SWITCHABLE_TARGET).

The disadvantage of:

   const target_types &targetm.get_type_data ()

is that it pushes the caching logic into targetm rather than sharing
it between all ports.  This could be a particular problem for targets
like MIPS that support a lot of variations.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
  2015-07-27  3:10 [PATCH 0/9] start converting POINTER_SIZE to a hook tbsaunde+gcc
                   ` (9 preceding siblings ...)
  2015-07-27  9:26 ` [PATCH 0/9] start converting POINTER_SIZE to a hook Richard Biener
@ 2015-07-29 10:40 ` Richard Earnshaw
  2015-07-30  4:55   ` Segher Boessenkool
  10 siblings, 1 reply; 25+ messages in thread
From: Richard Earnshaw @ 2015-07-29 10:40 UTC (permalink / raw)
  To: tbsaunde+gcc, gcc-patches

On 27/07/15 04:10, tbsaunde+gcc@tbsaunde.org wrote:
> From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
> 
> Hi,
> 
> $subject.
> 
> patches individually bootstrapped + regtested on x86_64-linux-gnu, and run
> through config-list.mk with more patches removing usage of the macro.  Ok?
> 
> Trev
> 
> Trevor Saunders (9):
>   remove POINTER_SIZE_UNITS macro
>   add pointer_size target hook
>   target.h: change to use targetm.pointer_size instead of POINTER_SIZE
>   varasm.c: switch from POINTER_SIZE to targetm.pointer_size ()
>   ubsan.c: switch from POINTER_SIZE to targetm.pointer_size ()
>   tree-chkp.c: switch to targetm.pointer_size ()
>   stor-layout.c: switch to targetm.pointer_size ()
>   tree.c: switch to targetm.pointer_size ()
>   emit-rtl.c: switch to targetm.pointer_size ()
> 
>  gcc/c-family/c-cppbuiltin.c |  2 +-
>  gcc/defaults.h              |  3 ---
>  gcc/doc/tm.texi             |  7 +++++++
>  gcc/doc/tm.texi.in          |  2 ++
>  gcc/dwarf2asm.c             |  4 ++--
>  gcc/emit-rtl.c              |  5 +++--
>  gcc/lto/lto-object.c        |  3 ++-
>  gcc/stor-layout.c           |  9 +++++----
>  gcc/target.def              |  8 ++++++++
>  gcc/target.h                |  8 ++++++++
>  gcc/targhooks.c             |  8 ++++++++
>  gcc/targhooks.h             |  1 +
>  gcc/tree-chkp.c             | 14 ++++++++------
>  gcc/tree.c                  |  3 ++-
>  gcc/ubsan.c                 |  3 ++-
>  gcc/varasm.c                | 12 ++++++------
>  16 files changed, 65 insertions(+), 27 deletions(-)
> 

I'm getting a bit worried about the potential performance impact from
all these indirect function call hooks.  This is a good example of when
it's probably somewhat unnecessary.  I doubt that the compiler could
function correctly if this ever changed in the middle of a function.

It would be much better if targetm.pointer_size was a variable that
could be modified by back-end code on those few occasions when that
might be really necessary.

R.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
  2015-07-29 10:40 ` Richard Earnshaw
@ 2015-07-30  4:55   ` Segher Boessenkool
  0 siblings, 0 replies; 25+ messages in thread
From: Segher Boessenkool @ 2015-07-30  4:55 UTC (permalink / raw)
  To: Richard Earnshaw; +Cc: tbsaunde+gcc, gcc-patches

On Wed, Jul 29, 2015 at 11:16:40AM +0100, Richard Earnshaw wrote:
> I'm getting a bit worried about the potential performance impact from
> all these indirect function call hooks.  This is a good example of when
> it's probably somewhat unnecessary.  I doubt that the compiler could
> function correctly if this ever changed in the middle of a function.

It is also very ugly and much harder to read: it is longer, with more
useless interpunction, and there is nothing that makes clear it is a
constant.


Segher

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
  2015-07-29  8:32             ` Richard Sandiford
@ 2015-07-30  8:13               ` Trevor Saunders
  2015-07-30 22:30                 ` Richard Sandiford
  0 siblings, 1 reply; 25+ messages in thread
From: Trevor Saunders @ 2015-07-30  8:13 UTC (permalink / raw)
  To: Jeff Law, Richard Biener, tbsaunde+gcc, GCC Patches, richard.sandiford

On Wed, Jul 29, 2015 at 09:11:21AM +0100, Richard Sandiford wrote:
> Trevor Saunders <tbsaunde@tbsaunde.org> writes:
> > On Tue, Jul 28, 2015 at 09:24:17PM +0100, Richard Sandiford wrote:
> >> Trevor Saunders <tbsaunde@tbsaunde.org> writes:
> >> > On Mon, Jul 27, 2015 at 09:05:08PM +0100, Richard Sandiford wrote:
> >> >> Alternatively we could have a new target_globals structure that is
> >> >> initialised with the result of calling the hook.  If we do that though,
> >> >> it might make sense to consolidate the hooks rather than have one for
> >> >> every value.  E.g. having one function for UNITS_PER_WORD, one for
> >> >> POINTER_SIZE, one for Pmode, etc., would lead to some very verbose
> >> >> target code.
> >> >
> >> > so something like
> >> >
> >> > struct target_types
> >> > {
> >> >   unsigned long pointer_size;
> >> >   ...
> >> > };
> >> >
> >> > const target_types &targetm.get_type_data ()
> >> >
> >> > ? that seems pretty reasonable, and I wouldn't expect too many ordering
> >> > issues, but who knows.  Its too bad nobody has taken on the big job of
> >> > turning targetm into a class so we can hope for some devirt help from
> >> > the compiler.
> >> 
> >> I was thinking more:
> >> 
> >>   void targetm.get_type_data (target_types *);
> >> 
> >> The caller could then initialise or post-process the defaults.  The
> >> target_types would eventually end up in some target_globals structure.
> >
> > but wouldn't that mean the hook would need to initialize all the fields
> > every time the hook was called?
> 
> Yeah, but the idea was that the hook would only be called once per
> target initialisation and the result would be stored in a target_globals
> structure.  Then places that use POINTER_SIZE would instead use the
> cached target_globals structure rather than targetm.

ok, personally I always found the have global state and update it
appropriately approach a little distasteful, but I have to admitt it
makes getting values faster than anything else, and otherwise works.  I
guess if we ever care about threaded compilation for the jit or whatever
that's not true, but that's not a bridge we need to cross now.

> For SWITCHABLE_TARGETs, the hook would be called only once for each
> subtarget used by the TU.  For other targets it would be called
> once for each change in subtarget (which is already very expensive without
> SWITCHABLE_TARGET -- targets that want it to be fast should move to
> SWITCHABLE_TARGET).
> 
> The disadvantage of:
> 
>    const target_types &targetm.get_type_data ()
> 
> is that it pushes the caching logic into targetm rather than sharing
> it between all ports.  This could be a particular problem for targets
> like MIPS that support a lot of variations.

true, though I was expecting for most targets you'd just have a couple
static const structs and just choose which one to return based onthe
subtarget which wouldn't be too bad.

Trev

> 
> Thanks,
> Richard
> 

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
  2015-07-30  8:13               ` Trevor Saunders
@ 2015-07-30 22:30                 ` Richard Sandiford
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Sandiford @ 2015-07-30 22:30 UTC (permalink / raw)
  To: Trevor Saunders
  Cc: Jeff Law, Richard Biener, tbsaunde+gcc, GCC Patches, richard.sandiford

Trevor Saunders <tbsaunde@tbsaunde.org> writes:
> On Wed, Jul 29, 2015 at 09:11:21AM +0100, Richard Sandiford wrote:
>> Trevor Saunders <tbsaunde@tbsaunde.org> writes:
>> > On Tue, Jul 28, 2015 at 09:24:17PM +0100, Richard Sandiford wrote:
>> >> Trevor Saunders <tbsaunde@tbsaunde.org> writes:
>> >> > On Mon, Jul 27, 2015 at 09:05:08PM +0100, Richard Sandiford wrote:
>> >> >> Alternatively we could have a new target_globals structure that is
>> >> >> initialised with the result of calling the hook.  If we do that though,
>> >> >> it might make sense to consolidate the hooks rather than have one for
>> >> >> every value.  E.g. having one function for UNITS_PER_WORD, one for
>> >> >> POINTER_SIZE, one for Pmode, etc., would lead to some very verbose
>> >> >> target code.
>> >> >
>> >> > so something like
>> >> >
>> >> > struct target_types
>> >> > {
>> >> >   unsigned long pointer_size;
>> >> >   ...
>> >> > };
>> >> >
>> >> > const target_types &targetm.get_type_data ()
>> >> >
>> >> > ? that seems pretty reasonable, and I wouldn't expect too many ordering
>> >> > issues, but who knows.  Its too bad nobody has taken on the big job of
>> >> > turning targetm into a class so we can hope for some devirt help from
>> >> > the compiler.
>> >> 
>> >> I was thinking more:
>> >> 
>> >>   void targetm.get_type_data (target_types *);
>> >> 
>> >> The caller could then initialise or post-process the defaults.  The
>> >> target_types would eventually end up in some target_globals structure.
>> >
>> > but wouldn't that mean the hook would need to initialize all the fields
>> > every time the hook was called?
>> 
>> Yeah, but the idea was that the hook would only be called once per
>> target initialisation and the result would be stored in a target_globals
>> structure.  Then places that use POINTER_SIZE would instead use the
>> cached target_globals structure rather than targetm.
>
> ok, personally I always found the have global state and update it
> appropriately approach a little distasteful, but I have to admitt it
> makes getting values faster than anything else, and otherwise works.  I
> guess if we ever care about threaded compilation for the jit or whatever
> that's not true, but that's not a bridge we need to cross now.

Yeah, and targetm isn't really any less global than the target_globals.
(The targetm fields aren't fixed.)

If we make GCC thread-safe or multi-target, I assume/hope we'd apply the
same approach to both targetm and the target_globals data.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
  2015-07-30 13:42 David Edelsohn
@ 2015-07-30 22:26 ` Richard Sandiford
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Sandiford @ 2015-07-30 22:26 UTC (permalink / raw)
  To: David Edelsohn; +Cc: Richard Earnshaw, tbsaunde+gcc, GCC Patches

David Edelsohn <dje.gcc@gmail.com> writes:
> On Wed, Jul 29, 2015 at 11:16:40AM +0100, Richard Earnshaw wrote:
>> I'm getting a bit worried about the potential performance impact from
>> all these indirect function call hooks.  This is a good example of when
>> it's probably somewhat unnecessary.  I doubt that the compiler could
>> function correctly if this ever changed in the middle of a function.
>
> +1

FWIW, the thread has already moved on from the idea of calling this hook
each time POINTER_SIZE is used.

The idea of caching POINTER_SIZE should if anything make things quicker,
since on many modern targets POINTER_SIZE depends on command-line options
and the values of those options are tested each time POINTER_SIZE is used.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 0/9] start converting POINTER_SIZE to a hook
@ 2015-07-30 13:42 David Edelsohn
  2015-07-30 22:26 ` Richard Sandiford
  0 siblings, 1 reply; 25+ messages in thread
From: David Edelsohn @ 2015-07-30 13:42 UTC (permalink / raw)
  To: Richard Earnshaw, tbsaunde+gcc; +Cc: GCC Patches

On Wed, Jul 29, 2015 at 11:16:40AM +0100, Richard Earnshaw wrote:
> I'm getting a bit worried about the potential performance impact from
> all these indirect function call hooks.  This is a good example of when
> it's probably somewhat unnecessary.  I doubt that the compiler could
> function correctly if this ever changed in the middle of a function.

+1

- David

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2015-07-30 21:37 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-27  3:10 [PATCH 0/9] start converting POINTER_SIZE to a hook tbsaunde+gcc
2015-07-27  3:10 ` [PATCH 9/9] emit-rtl.c: switch to targetm.pointer_size () tbsaunde+gcc
2015-07-27  3:10 ` [PATCH 2/9] add pointer_size target hook tbsaunde+gcc
2015-07-27  3:10 ` [PATCH 7/9] stor-layout.c: switch to targetm.pointer_size () tbsaunde+gcc
2015-07-27  3:10 ` [PATCH 3/9] target.h: change to use targetm.pointer_size instead of POINTER_SIZE tbsaunde+gcc
2015-07-27  3:10 ` [PATCH 4/9] varasm.c: switch from POINTER_SIZE to targetm.pointer_size () tbsaunde+gcc
2015-07-27  9:32   ` Richard Biener
2015-07-27  3:10 ` [PATCH 1/9] remove POINTER_SIZE_UNITS macro tbsaunde+gcc
2015-07-27  3:10 ` [PATCH 5/9] ubsan.c: switch from POINTER_SIZE to targetm.pointer_size () tbsaunde+gcc
2015-07-27  3:42 ` [PATCH 6/9] tree-chkp.c: switch " tbsaunde+gcc
2015-07-27  3:49 ` [PATCH 8/9] tree.c: " tbsaunde+gcc
2015-07-27  9:26 ` [PATCH 0/9] start converting POINTER_SIZE to a hook Richard Biener
2015-07-27 16:20   ` Jeff Law
2015-07-27 20:15     ` Richard Sandiford
2015-07-28  5:52       ` Trevor Saunders
2015-07-28 20:36         ` Richard Sandiford
2015-07-29  4:44           ` Trevor Saunders
2015-07-29  8:32             ` Richard Sandiford
2015-07-30  8:13               ` Trevor Saunders
2015-07-30 22:30                 ` Richard Sandiford
2015-07-28  3:47     ` Trevor Saunders
2015-07-29 10:40 ` Richard Earnshaw
2015-07-30  4:55   ` Segher Boessenkool
2015-07-30 13:42 David Edelsohn
2015-07-30 22:26 ` Richard Sandiford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).