[committed] Add {target ,}{teams ,parallel ,}loop construct support

2019-07-20 Thread Jakub Jelinek
Hi!

The following patch adds support for the OpenMP loop construct and
constructs combined with it.  Depending on the binding, it is for now
lowered to distribute parallel for simd, for simd or simd.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2019-07-20  Jakub Jelinek  

* tree.def (OMP_LOOP): New tree code.
* tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_BIND.
(enum omp_clause_bind_kind): New enum.
(struct tree_omp_clause): Add subcode.bind_kind.
* tree.h (OMP_LOOP_CHECK): Rename to ...
(OMP_LOOPING_CHECK): ... this.
(OMP_FOR_BODY, OMP_FOR_CLAUSES, OMP_FOR_INIT, OMP_FOR_COND,
OMP_FOR_INCR, OMP_FOR_PRE_BODY, OMP_FOR_ORIG_DECLS): Use
OMP_LOOPING_CHECK instead of OMP_LOOP_CHECK.
(OMP_CLAUSE_BIND_KIND): Define.
* tree.c (omp_clause_num_ops, omp_clause_code_name): Add
bind clause entries.
(walk_tree_1): Handle OMP_CLAUSE_BIND.
* tree-pretty-print.c (dump_omp_clause): Likewise.
(dump_generic_node): Handle OMP_LOOP.
* gimplify.c (enum omp_region_type): Add ORT_IMPLICIT_TARGET.
(in_omp_construct): New variable.
(is_gimple_stmt): Handle OMP_LOOP.
(gimplify_scan_omp_clauses): For lastprivate don't set
check_non_private if code == OMP_LOOP.  For reduction clause
on OMP_LOOP combined with parallel or teams propagate as shared
on the combined construct.  Handle OMP_CLAUSE_BIND.
(gimplify_adjust_omp_clauses): Handle OMP_CLAUSE_BIND.
(gimplify_omp_for): Pass OMP_LOOP instead of OMP_{FOR,DISTRIBUTE}
for constructs from a loop construct to gimplify_scan_omp_clauses.
Don't predetermine iterator linear on OMP_SIMD from loop construct.
(replace_reduction_placeholders, gimplify_omp_loop): New functions.
(gimplify_omp_workshare): Use ORT_IMPLICIT_TARGET instead of trying
to match the implicit ORT_TARGET construct around whole body.
Temporarily clear in_omp_construct when processing body.
(gimplify_expr): Handle OMP_LOOP.  For OMP_MASTER, OMP_TASKGROUP
etc. temporarily set in_omp_construct when processing body.
(gimplify_body): Create ORT_IMPLICIT_TARGET instead of ORT_TARGET.
* omp-low.c (struct omp_context): Add loop_p.
(build_outer_var_ref): Treat ctx->loop_p similarly to simd construct
in that the original var might be private.
(scan_sharing_clauses): Handle OMP_CLAUSE_BIND.
(check_omp_nesting_restrictions): Adjust nesting restrictions for
addition of loop construct.
(scan_omp_1_stmt): Allow setjmp inside of loop construct.
gcc/c-family/
* c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_LOOP.
(enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_BIND.
* c-pragma.c (omp_pragmas_simd): Add PRAGMA_OMP_LOOP entry.
* c-common.h (enum c_omp_clause_split): Add C_OMP_CLAUSE_SPLIT_LOOP.
* c-omp.c (c_omp_split_clauses): Add support for 4 new combined
constructs with the loop construct.
gcc/c/
* c-parser.c (c_parser_omp_clause_name): Handle bind clause.
(c_parser_omp_clause_bind): New function.
(c_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_BIND.
(OMP_LOOP_CLAUSE_MASK): Define.
(c_parser_omp_loop): New function.
(c_parser_omp_parallel, c_parser_omp_teams): Handle parsing of
loop combined with parallel or teams.
(c_parser_omp_construct): Handle PRAGMA_OMP_LOOP.
* c-typeck.c (c_finish_omp_clauses): Handle OMP_CLAUSE_BIND.
gcc/cp/
* cp-tree.h (OMP_FOR_GIMPLIFYING_P): Use OMP_LOOPING_CHECK
instead of OMP_LOOP_CHECK.
* parser.c (cp_parser_omp_clause_name): Handle bind clause.
(cp_parser_omp_clause_bind): New function.
(cp_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_BIND.
(OMP_LOOP_CLAUSE_MASK): Define.
(cp_parser_omp_loop): New function.
(cp_parser_omp_parallel, cp_parser_omp_teams): Handle parsing of
loop combined with parallel or teams.
(cp_parser_omp_construct): Handle PRAGMA_OMP_LOOP.
(cp_parser_pragma): Likewise.
* pt.c (tsubst_expr): Handle OMP_LOOP.
* semantics.c (finish_omp_clauses): Handle OMP_CLAUSE_BIND.
gcc/testsuite/
* c-c++-common/gomp/cancel-1.c: Adjust expected diagnostic wording.
* c-c++-common/gomp/clauses-1.c (foo, baz, bar): Add order(concurrent)
clause where allowed.  Add combined constructs with loop with all
possible clauses.
(qux): New function.
* c-c++-common/gomp/loop-1.c: New test.
* c-c++-common/gomp/loop-2.c: New test.
* c-c++-common/gomp/loop-3.c: New test.
* c-c++-common/gomp/loop-4.c: New test.
* c-c++-common/gomp/loop-5.c: New test.
* c-c++-common/gomp/order-3.c: Adjust expected diagnostic wording.
* c-c++-common/gomp/simd-setjmp-1.c: N

[C++ PATCH] Reduce memory consumption for push/pop_access_scope.

2019-07-20 Thread Jason Merrill
I was seeing memory consumption issues on the concepts-cxx2a
branch. push_scope was, surprisingly, at the top of -fmem-report, and
push_access_scope was pretty high.  Fixing them was pretty simple.

Tested x86_64-pc-linux-gnu, applying to trunk.

* name-lookup.c (leave_scope): Do add class levels other than
previous_class_level to free_binding_level.
(invalidate_class_lookup_cache): Move from class.c, add to
free_binding_level.
* pt.c (saved_access_scope): Change from list to vec.
---
 gcc/cp/class.c   | 10 --
 gcc/cp/name-lookup.c | 14 +-
 gcc/cp/pt.c  | 10 +++---
 gcc/cp/ChangeLog |  9 +
 4 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index f77b7f4834b..b61152c7e72 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -7588,16 +7588,6 @@ pushclass (tree type)
 restore_class_cache ();
 }
 
-/* When we exit a toplevel class scope, we save its binding level so
-   that we can restore it quickly.  Here, we've entered some other
-   class, so we must invalidate our cache.  */
-
-void
-invalidate_class_lookup_cache (void)
-{
-  previous_class_level = NULL;
-}
-
 /* Get out of the current class scope. If we were in a class scope
previously, that is the one popped to.  */
 
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index ad866298fa5..9f278220df3 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -3392,7 +3392,7 @@ leave_scope (void)
  namespace.  For classes, we cache some binding levels.  For other
  scopes, we just make the structure available for reuse.  */
   if (scope->kind != sk_namespace
-  && scope->kind != sk_class)
+  && scope != previous_class_level)
 {
   scope->level_chain = free_binding_level;
   gcc_assert (!ENABLE_SCOPE_CHECKING
@@ -3420,6 +3420,18 @@ leave_scope (void)
   return current_binding_level;
 }
 
+/* When we exit a toplevel class scope, we save its binding level so
+   that we can restore it quickly.  Here, we've entered some other
+   class, so we must invalidate our cache.  */
+
+void
+invalidate_class_lookup_cache (void)
+{
+  previous_class_level->level_chain = free_binding_level;
+  free_binding_level = previous_class_level;
+  previous_class_level = NULL;
+}
+
 static void
 resume_scope (cp_binding_level* b)
 {
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index b6eda7eb27c..deaac576468 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -67,7 +67,7 @@ static vec inline_parm_levels;
 
 static GTY(()) struct tinst_level *current_tinst_level;
 
-static GTY(()) tree saved_access_scope;
+static GTY(()) vec *saved_access_scope;
 
 /* Live only within one (recursive) call to tsubst_expr.  We use
this to pass the statement expression node from the STMT_EXPR
@@ -247,8 +247,7 @@ push_access_scope (tree t)
 
   if (TREE_CODE (t) == FUNCTION_DECL)
 {
-  saved_access_scope = tree_cons
-   (NULL_TREE, current_function_decl, saved_access_scope);
+  vec_safe_push (saved_access_scope, current_function_decl);
   current_function_decl = t;
 }
 }
@@ -260,10 +259,7 @@ static void
 pop_access_scope (tree t)
 {
   if (TREE_CODE (t) == FUNCTION_DECL)
-{
-  current_function_decl = TREE_VALUE (saved_access_scope);
-  saved_access_scope = TREE_CHAIN (saved_access_scope);
-}
+current_function_decl = saved_access_scope->pop();
 
   if (DECL_FRIEND_CONTEXT (t) || DECL_CLASS_SCOPE_P (t))
 pop_nested_class ();
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c776243d973..0c6a7de94d9 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,12 @@
+2019-07-20  Jason Merrill  
+
+   Reduce memory consumption for push/pop_access_scope.
+   * name-lookup.c (leave_scope): Do add class levels other than
+   previous_class_level to free_binding_level.
+   (invalidate_class_lookup_cache): Move from class.c, add to
+   free_binding_level.
+   * pt.c (saved_access_scope): Change from list to vec.
+
 2019-07-20  Jakub Jelinek  
 
* cp-tree.h (OMP_FOR_GIMPLIFYING_P): Use OMP_LOOPING_CHECK

base-commit: 31890b5844874e62a52e52b4edf6fc558a9dc8d6
-- 
2.21.0



[C++ PATCH] Fix ICE on class template argument deduction with inherited ctor.

2019-07-20 Thread Jason Merrill
In general, when we see a dependent using-declaration we don't know whether
it names a function or not, so it doesn't get an OVERLOAD unless we see
overloads of the same name in the current class.  In the case of an
inherited constructor we could figure that out from the name, but it's
simpler to handle USING_DECL properly.

Tested x86_64-pc-linux-gnu, applying to trunk.

* cp-tree.h (ovl_iterator::using_p): A USING_DECL by itself was also
introduced by a using-declaration.
---
 gcc/cp/cp-tree.h  |  3 ++-
 .../g++.dg/cpp1z/class-deduction67.C  | 21 +++
 gcc/cp/ChangeLog  |  5 +
 3 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction67.C

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 6068745567a..688924cdd12 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -774,7 +774,8 @@ class ovl_iterator
   /* Whether this overload was introduced by a using decl.  */
   bool using_p () const
   {
-return TREE_CODE (ovl) == OVERLOAD && OVL_USING_P (ovl);
+return (TREE_CODE (ovl) == USING_DECL
+   || (TREE_CODE (ovl) == OVERLOAD && OVL_USING_P (ovl)));
   }
   bool hidden_p () const
   {
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction67.C 
b/gcc/testsuite/g++.dg/cpp1z/class-deduction67.C
new file mode 100644
index 000..4624794c4b7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction67.C
@@ -0,0 +1,21 @@
+// Deduction from inherited constructors isn't supported yet, but we shouldn't
+// crash.  It may well be supported in C++23.
+
+//{ dg-do compile { target c++17 } }
+
+template  struct A
+{
+  A(T);
+};
+
+template  struct B: A
+{
+  using A::A;
+};
+
+int main()
+{
+  B b = 42;// { dg-line init }
+  // { dg-prune-output "no matching function" }
+  // { dg-error "class template argument deduction" "" { target *-*-* } init }
+}
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0c6a7de94d9..d645cdef147 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2019-07-20  Jason Merrill  
+
+   * cp-tree.h (ovl_iterator::using_p): A USING_DECL by itself was also
+   introduced by a using-declaration.
+
 2019-07-20  Jason Merrill  
 
Reduce memory consumption for push/pop_access_scope.

base-commit: 8086cf948309ce8a2a353e0d483b9a14c9f83cc6
-- 
2.21.0



[PATCH], Patch #10, move PowerPC data structures & helper functions from rs6000.c to rs6000-internal.h

2019-07-20 Thread Michael Meissner
I will be iterating on patch #9 and sending out a replacement shortly.

This is patch #10.  It moves the various data structures from rs6000.c to
rs6000-internal.h.  In the future, it will allow us to move more things from
rs6000.c to other files.  In particular, I plan on adding a rs6000-prefixed.c
file that has the specific support for prefixed instructions.

It would also allow various functions for handling adressing and register
assignment, etc. that could also be moved to a separate file as well.

This patch just moves the data structure definitions and helper functions
(mode_supports_*) to rs6000-internal.h.  The static data structures are changed
to external, and definitions of the function are put in rs6000.c.  I did add 00
to the bit mask definitions for RELOAD_REG_* because I plan to add at least one
more mask (for DS-form addresses) in the future, and it will the values lined
up.

I have done a bootstrap on a little endian power8 system running Linux and
there were no regressions in the test suite.  Can I check this into the trunk?

2019-07-20  Michael Meissner  

* config/rs6000/rs6000-internal.h (rs6000_hard_regno_mode_ok_p):
Move various declarations relating to addressing and register
allocation to rs6000-internal.h from rs6000.c so that in the
future we can move things out of rs6000.c.  Make the static arrays
global, and define them in rs6000.c.
(enum rs6000_reg_type): Likewise.
(reg_class_to_reg_type): Likewise.
(IS_STD_REG_TYPE): Likewise.
(IS_FP_VECT_REG_TYPE): Likewise.
(enum rs6000_reload_reg_type): Likewise.
(FIRST_RELOAD_REG_CLASS): Likewise.
(LAST_RELOAD_REG_CLASS): Likewise.
(struct reload_reg_map_type): Likewise.
(reload_reg_map): Likewise.
(RELOAD_REG_* macros): Likewise.
(struct rs6000_reg_addr): Likewise.
(reg_addr): Likewise.
(mode_supports_pre_incdec_): Likewise.
(mode_supports_pre_modify_p): Likewise.
(mode_supports_vmx_dform): Likewise.
(mode_supports_dq_form): Likewise.
(mode_supports_prefixed_address_p): Likewise.
* config/rs6000/rs6000.c (rs6000_hard_regno_mode_ok_p): Likewise.
(enum rs6000_reg_type): Likewise.
(reg_class_to_reg_type): Likewise.
(IS_STD_REG_TYPE): Likewise.
(IS_FP_VECT_REG_TYPE): Likewise.
(enum rs6000_reload_reg_type): Likewise.
(FIRST_RELOAD_REG_CLASS): Likewise.
(LAST_RELOAD_REG_CLASS): Likewise.
(struct reload_reg_map_type): Likewise.
(reload_reg_map): Likewise.
(RELOAD_REG_* macros): Likewise.
(struct rs6000_reg_addr): Likewise.
(reg_addr): Likewise.
(mode_supports_pre_incdec_): Likewise.
(mode_supports_pre_modify_p): Likewise.
(mode_supports_vmx_dform): Likewise.
(mode_supports_dq_form): Likewise.
(mode_supports_prefixed_address_p): Likewise.

Index: gcc/config/rs6000/rs6000-internal.h
===
--- gcc/config/rs6000/rs6000-internal.h (revision 273617)
+++ gcc/config/rs6000/rs6000-internal.h (working copy)
@@ -22,6 +22,134 @@
 #ifndef GCC_RS6000_INTERNAL_H
 #define GCC_RS6000_INTERNAL_H
 
+/* Value is TRUE if register/mode pair is acceptable.  */
+extern bool rs6000_hard_regno_mode_ok_p
+  [NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
+
+/* Simplfy register classes into simpler classifications.  We assume
+   GPR_REG_TYPE - FPR_REG_TYPE are ordered so that we can use a simple range
+   check for standard register classes (gpr/floating/altivec/vsx) and
+   floating/vector classes (float/altivec/vsx).  */
+
+enum rs6000_reg_type {
+  NO_REG_TYPE,
+  PSEUDO_REG_TYPE,
+  GPR_REG_TYPE,
+  VSX_REG_TYPE,
+  ALTIVEC_REG_TYPE,
+  FPR_REG_TYPE,
+  SPR_REG_TYPE,
+  CR_REG_TYPE
+};
+
+/* Map register class to register type.  */
+extern enum rs6000_reg_type reg_class_to_reg_type[N_REG_CLASSES];
+
+/* First/last register type for the 'normal' register types (i.e. general
+   purpose, floating point, altivec, and VSX registers).  */
+#define IS_STD_REG_TYPE(RTYPE) IN_RANGE(RTYPE, GPR_REG_TYPE, FPR_REG_TYPE)
+
+#define IS_FP_VECT_REG_TYPE(RTYPE) IN_RANGE(RTYPE, VSX_REG_TYPE, FPR_REG_TYPE)
+
+
+/* Register classes we care about in secondary reload or go if legitimate
+   address.  We only need to worry about GPR, FPR, and Altivec registers here,
+   along an ANY field that is the OR of the 3 register classes.  */
+
+enum rs6000_reload_reg_type {
+  RELOAD_REG_GPR,  /* General purpose registers.  */
+  RELOAD_REG_FPR,  /* Traditional floating point regs.  */
+  RELOAD_REG_VMX,  /* Altivec (VMX) registers.  */
+  RELOAD_REG_ANY,  /* OR of GPR, FPR, Altivec masks.  */
+  N_RELOAD_REG
+};
+
+/* For setting up register classes, loop through the 3 register classes mapping
+   into real registers, and skip the ANY class, wh

Re: [PATCH], Patch #10, move PowerPC data structures & helper functions from rs6000.c to rs6000-internal.h

2019-07-20 Thread David Edelsohn
On Sat, Jul 20, 2019 at 12:13 PM Michael Meissner
 wrote:
>
> I will be iterating on patch #9 and sending out a replacement shortly.
>
> This is patch #10.  It moves the various data structures from rs6000.c to
> rs6000-internal.h.  In the future, it will allow us to move more things from
> rs6000.c to other files.  In particular, I plan on adding a rs6000-prefixed.c
> file that has the specific support for prefixed instructions.
>
> It would also allow various functions for handling adressing and register
> assignment, etc. that could also be moved to a separate file as well.
>
> This patch just moves the data structure definitions and helper functions
> (mode_supports_*) to rs6000-internal.h.  The static data structures are 
> changed
> to external, and definitions of the function are put in rs6000.c.  I did add 
> 00
> to the bit mask definitions for RELOAD_REG_* because I plan to add at least 
> one
> more mask (for DS-form addresses) in the future, and it will the values lined
> up.
>
> I have done a bootstrap on a little endian power8 system running Linux and
> there were no regressions in the test suite.  Can I check this into the trunk?

This patch needs to add rs6000-internal.h to tm_file in gcc/config.gcc
for all of the powerpc/rs6000 targets.  It also may need tm_p_file and
tm_d_file definitions.

Thanks, David

>
> 2019-07-20  Michael Meissner  
>
> * config/rs6000/rs6000-internal.h (rs6000_hard_regno_mode_ok_p):
> Move various declarations relating to addressing and register
> allocation to rs6000-internal.h from rs6000.c so that in the
> future we can move things out of rs6000.c.  Make the static arrays
> global, and define them in rs6000.c.
> (enum rs6000_reg_type): Likewise.
> (reg_class_to_reg_type): Likewise.
> (IS_STD_REG_TYPE): Likewise.
> (IS_FP_VECT_REG_TYPE): Likewise.
> (enum rs6000_reload_reg_type): Likewise.
> (FIRST_RELOAD_REG_CLASS): Likewise.
> (LAST_RELOAD_REG_CLASS): Likewise.
> (struct reload_reg_map_type): Likewise.
> (reload_reg_map): Likewise.
> (RELOAD_REG_* macros): Likewise.
> (struct rs6000_reg_addr): Likewise.
> (reg_addr): Likewise.
> (mode_supports_pre_incdec_): Likewise.
> (mode_supports_pre_modify_p): Likewise.
> (mode_supports_vmx_dform): Likewise.
> (mode_supports_dq_form): Likewise.
> (mode_supports_prefixed_address_p): Likewise.
> * config/rs6000/rs6000.c (rs6000_hard_regno_mode_ok_p): Likewise.
> (enum rs6000_reg_type): Likewise.
> (reg_class_to_reg_type): Likewise.
> (IS_STD_REG_TYPE): Likewise.
> (IS_FP_VECT_REG_TYPE): Likewise.
> (enum rs6000_reload_reg_type): Likewise.
> (FIRST_RELOAD_REG_CLASS): Likewise.
> (LAST_RELOAD_REG_CLASS): Likewise.
> (struct reload_reg_map_type): Likewise.
> (reload_reg_map): Likewise.
> (RELOAD_REG_* macros): Likewise.
> (struct rs6000_reg_addr): Likewise.
> (reg_addr): Likewise.
> (mode_supports_pre_incdec_): Likewise.
> (mode_supports_pre_modify_p): Likewise.
> (mode_supports_vmx_dform): Likewise.
> (mode_supports_dq_form): Likewise.
> (mode_supports_prefixed_address_p): Likewise.
>
> Index: gcc/config/rs6000/rs6000-internal.h
> ===
> --- gcc/config/rs6000/rs6000-internal.h (revision 273617)
> +++ gcc/config/rs6000/rs6000-internal.h (working copy)
> @@ -22,6 +22,134 @@
>  #ifndef GCC_RS6000_INTERNAL_H
>  #define GCC_RS6000_INTERNAL_H
>
> +/* Value is TRUE if register/mode pair is acceptable.  */
> +extern bool rs6000_hard_regno_mode_ok_p
> +  [NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
> +
> +/* Simplfy register classes into simpler classifications.  We assume
> +   GPR_REG_TYPE - FPR_REG_TYPE are ordered so that we can use a simple range
> +   check for standard register classes (gpr/floating/altivec/vsx) and
> +   floating/vector classes (float/altivec/vsx).  */
> +
> +enum rs6000_reg_type {
> +  NO_REG_TYPE,
> +  PSEUDO_REG_TYPE,
> +  GPR_REG_TYPE,
> +  VSX_REG_TYPE,
> +  ALTIVEC_REG_TYPE,
> +  FPR_REG_TYPE,
> +  SPR_REG_TYPE,
> +  CR_REG_TYPE
> +};
> +
> +/* Map register class to register type.  */
> +extern enum rs6000_reg_type reg_class_to_reg_type[N_REG_CLASSES];
> +
> +/* First/last register type for the 'normal' register types (i.e. general
> +   purpose, floating point, altivec, and VSX registers).  */
> +#define IS_STD_REG_TYPE(RTYPE) IN_RANGE(RTYPE, GPR_REG_TYPE, FPR_REG_TYPE)
> +
> +#define IS_FP_VECT_REG_TYPE(RTYPE) IN_RANGE(RTYPE, VSX_REG_TYPE, 
> FPR_REG_TYPE)
> +
> +
> +/* Register classes we care about in secondary reload or go if legitimate
> +   address.  We only need to worry about GPR, FPR, and Altivec registers 
> here,
> +   along an ANY field that is the OR of the 3 register classes.  */
> +
> +enum rs6000_reload_reg_type 

Re: [PATCH]: Fix ICE in expand_expr_real_2 (PR target/91204)

2019-07-20 Thread Richard Biener
On July 20, 2019 8:45:38 AM GMT+02:00, Jakub Jelinek  wrote:
>On Fri, Jul 19, 2019 at 04:41:06PM +0200, Uros Bizjak wrote:
>> As suggested by Jakub in the PR, add missing vector one_cmpl2
>to
>> mmx.md. A generic fix is in the works by Jakub.
>
>Yes, here it is.  Bootstrapped/regtested on x86_64-linux and
>i686-linux, ok
>for trunk?

Ok. 

Richard. 

>2019-07-20  Jakub Jelinek  
>
>   PR target/91204
>   * optabs.c (expand_unop): As fallback, expand ~op0 as op0 ^ -1.
>
>   * gcc.c-torture/compile/pr91204.c: New test.
>
>--- gcc/optabs.c.jj2019-07-15 10:53:10.743205405 +0200
>+++ gcc/optabs.c   2019-07-19 00:38:20.271852242 +0200
>@@ -2972,6 +2972,17 @@ expand_unop (machine_mode mode, optab un
>   return target;
> }
> 
>+  /* Emit ~op0 as op0 ^ -1.  */
>+  if (unoptab == one_cmpl_optab
>+  && (SCALAR_INT_MODE_P (mode) || GET_MODE_CLASS (mode) ==
>MODE_VECTOR_INT)
>+  && optab_handler (xor_optab, mode) != CODE_FOR_nothing)
>+{
>+  temp = expand_binop (mode, xor_optab, op0, CONSTM1_RTX (mode),
>+ target, unsignedp, OPTAB_DIRECT);
>+  if (temp)
>+  return temp;
>+}
>+
>   if (optab_to_code (unoptab) == NEG)
> {
>/* Try negating floating point values by flipping the sign bit.  */
>--- gcc/testsuite/gcc.c-torture/compile/pr91204.c.jj   2019-07-19
>09:29:32.366011373 +0200
>+++ gcc/testsuite/gcc.c-torture/compile/pr91204.c  2019-07-19
>09:29:11.011340662 +0200
>@@ -0,0 +1,11 @@
>+/* PR target/91204 */
>+
>+int a, b, c[64];
>+
>+void
>+foo (void)
>+{
>+  int i;
>+  for (i = 2; i < 64; i++)
>+c[i] &= b ^ c[i] ^ c[i - 2];
>+}
>
>
>   Jakub



Re: [PATCH,fortran] Handle BOZ in accordance to Fortran 2018 standard

2019-07-20 Thread Jerry DeLisle

On 7/17/19 8:32 PM, Steve Kargl wrote:

I will be away until Monday.  Plenty of time for a review.




---snip --

Something not quite right here in this comment.


+/* A BOZ literal constant can appear in a limited number of contexts.
+   gfc_invalid_boz() is a help function to simplify error/warning generation.
+   Note, gfortran accepts the nonstandard 'X' for 'Z' the nonstandard
  ^<<< in >>?
+   suffix location.  If -fallow-invalid-boz is used, then issue a warning;
+   otherwise issue an error.  */

--- snip

+  /* FIXME BOZ.  What to do with complex?  */

Is your question here regarding whether to treat the two real storage locations 
as one single area and pad? Or to duplicate one BOZ pattern into each? Or 
require two BOZ patterns to be provided? or something else?


--- snip ---

-
+  /* FIXME BOZ.  */
   if (!gfc_in_match_data ()
   && (!gfc_notify_std(GFC_STD_F2003, "BOZ used outside a DATA "
- "statement at %C")))
-  return MATCH_ERROR;
+ "statement at %L", &e->where)))
+return MATCH_ERROR;

Maybe expand the comment a bit to better hint at the issue.

--- snip ---

The patch applies cleanly and tests OK on my machines here. I am very much in 
favor of deprecating LONG and SHORT which are way too ambiguous.


I say OK to commit.

Regards,

Jerry



[PATCH] parisc: Move declaration.

2019-07-20 Thread John David Anglin
This patch moves to declaration of hppa_profile_hook to pa-protos.h.

Tested on hppa-unknown-linux-gnu.  Committed to trunk.

Dave
-- 
John David Anglin  dave.ang...@bell.net

2019-07-20  John David Anglin  

* config/pa/pa.h (hppa_profile_hook): Delete declaration.
* config/pa/pa-protos.h (hppa_profile_hook): Add declaration.

Index: config/pa/pa.h
===
--- config/pa/pa.h  (revision 273562)
+++ config/pa/pa.h  (working copy)
@@ -666,7 +666,6 @@
   (*targetm.asm_out.internal_label) (FILE, FUNC_BEGIN_PROLOG_LABEL, LABEL)

 #define PROFILE_HOOK(label_no) hppa_profile_hook (label_no)
-void hppa_profile_hook (int label_no);

 /* The profile counter if emitted must come before the prologue.  */
 #define PROFILE_BEFORE_PROLOGUE 1
Index: config/pa/pa-protos.h
===
--- config/pa/pa-protos.h   (revision 273562)
+++ config/pa/pa-protos.h   (working copy)
@@ -109,6 +109,7 @@
 extern HOST_WIDE_INT pa_initial_elimination_offset (int, int);
 extern HOST_WIDE_INT pa_function_arg_size (machine_mode, const_tree);
 extern void pa_output_function_label (FILE *);
+extern void hppa_profile_hook (int);

 extern const int pa_magic_milli[];



[PATCH 1/4] rs6000: New predicate any_memory_operand

2019-07-20 Thread Segher Boessenkool
The new predicate accepts both memory_operand and volatile_mem_operand.


2019-07-20  Segher Boessenkool  

* config/rs6000/predicates.md (volatile_mem_operand): Modernize syntax.
(any_memory_operand): New predicate.
(reg_or_mem_operand): Use it.

---
 gcc/config/rs6000/predicates.md | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index 5f687ea..13c7c02 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -703,12 +703,17 @@ (define_predicate "zero_fp_constant"
 ;; memory references.  So this function allows us to recognize volatile
 ;; references where it's safe.
 (define_predicate "volatile_mem_operand"
-  (and (and (match_code "mem")
-   (match_test "MEM_VOLATILE_P (op)"))
+  (and (match_code "mem")
+   (match_test "MEM_VOLATILE_P (op)")
(if_then_else (match_test "reload_completed")
 (match_operand 0 "memory_operand")
 (match_test "memory_address_p (mode, XEXP (op, 0))"
 
+;; Return 1 if the operand is a volatile or non-volatile memory operand.
+(define_predicate "any_memory_operand"
+  (ior (match_operand 0 "memory_operand")
+   (match_operand 0 "volatile_mem_operand")))
+
 ;; Return 1 if the operand is an offsettable memory operand.
 (define_predicate "offsettable_mem_operand"
   (and (match_operand 0 "memory_operand")
@@ -891,11 +896,10 @@ (define_predicate "scc_eq_operand"
 
 ;; Return 1 if the operand is a general non-special register or memory operand.
 (define_predicate "reg_or_mem_operand"
-  (ior (match_operand 0 "memory_operand")
+  (ior (match_operand 0 "gpc_reg_operand")
+   (match_operand 0 "any_memory_operand")
(and (match_code "mem")
-   (match_test "macho_lo_sum_memory_operand (op, mode)"))
-   (match_operand 0 "volatile_mem_operand")
-   (match_operand 0 "gpc_reg_operand")))
+   (match_test "macho_lo_sum_memory_operand (op, mode)"
 
 ;; Return 1 if the operand is CONST_DOUBLE 0, register or memory operand.
 (define_predicate "zero_reg_mem_operand"
-- 
1.8.3.1



[PATCH 0/4] rs6000: Improve volatile memory handling

2019-07-20 Thread Segher Boessenkool
Most of our loads and stores are atomic when done on aligned operands.
This patch series cleans up our handling of that a little bit, and makes
us handle a few more cases.

The lwa_operand one has a testcase, which is how I noticed this could
use some improvement.  Looking at the combine dump for that shows
input_operand isn't handled properly, either.  And finally there is
offsettable_mem_operand as well.  I didn't see any other memory
operands we should handle as volatile as well, but who knows :-)

Tested on powerpc64-linux {-m32,-m64}; committing to trunk.


Segher


Segher Boessenkool (4):
  rs6000: New predicate any_memory_operand
  rs6000: Make lwa_operand use any_memory_operand
  rs6000: Make input_operand use any_memory_operand
  rs6000: Make offsettable_mem_operand use any_memory_operand

 gcc/config/rs6000/predicates.md | 22 +-
 gcc/testsuite/gcc.target/powerpc/volatile-mem.c | 16 
 2 files changed, 29 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/volatile-mem.c

-- 
1.8.3.1



[PATCH 4/4] rs6000: Make offsettable_mem_operand use any_memory_operand

2019-07-20 Thread Segher Boessenkool
2019-07-20  Segher Boessenkool  

* config/rs6000/predicates.md (offsettable_mem_operand): Allow volatile
memory.

---
 gcc/config/rs6000/predicates.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index 7c451df..5a2d2d3 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -716,7 +716,7 @@ (define_predicate "any_memory_operand"
 
 ;; Return 1 if the operand is an offsettable memory operand.
 (define_predicate "offsettable_mem_operand"
-  (and (match_operand 0 "memory_operand")
+  (and (match_operand 0 "any_memory_operand")
(match_test "offsettable_nonstrict_memref_p (op)")))
 
 ;; Return 1 if the operand is a simple offsettable memory operand
-- 
1.8.3.1



[PATCH 2/4] rs6000: Make lwa_operand use any_memory_operand

2019-07-20 Thread Segher Boessenkool
Testcase from comex, see https://lwn.net/Articles/793932/ .


2019-07-20  Segher Boessenkool  

* config/rs6000/predicates.md (lwa_operand): Allow volatile memory.

gcc/testsuite/
* gcc.target/powerpc/volatile-mem.c: New testcase.

---
 gcc/config/rs6000/predicates.md |  2 +-
 gcc/testsuite/gcc.target/powerpc/volatile-mem.c | 16 
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/volatile-mem.c

diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index 13c7c02..23d626b 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -929,7 +929,7 @@ (define_predicate "lwa_operand"
 
   if (gpc_reg_operand (inner, mode))
 return true;
-  if (!memory_operand (inner, mode))
+  if (!any_memory_operand (inner, mode))
 return false;
 
   addr = XEXP (inner, 0);
diff --git a/gcc/testsuite/gcc.target/powerpc/volatile-mem.c 
b/gcc/testsuite/gcc.target/powerpc/volatile-mem.c
new file mode 100644
index 000..c8a7444
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/volatile-mem.c
@@ -0,0 +1,16 @@
+/* { dg-options "-O2 -std=c11" } */
+/* { dg-require-effective-target lp64 } */
+
+/* This tests if the instructions used for C atomic are optimised properly
+   as atomic by the target code, too.  */
+
+#include 
+
+int load(_Atomic int *ptr)
+{
+return atomic_load_explicit(ptr, memory_order_relaxed);
+}
+
+/* There should be only two machine instructions, an lwa and a blr: */
+/* { dg-final { scan-assembler-times {(?n)^\s+[a-z]} 2 } } */
+/* { dg-final { scan-assembler-times {\mlwa\M} 1 } } */
-- 
1.8.3.1



[PATCH 3/4] rs6000: Make input_operand use any_memory_operand

2019-07-20 Thread Segher Boessenkool
2019-07-20  Segher Boessenkool  

* config/rs6000/predicates.md (input_operand): Allow volatile memory.

---
 gcc/config/rs6000/predicates.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index 23d626b..7c451df 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -1031,7 +1031,7 @@ (define_predicate "input_operand"
   const_double,const_wide_int,const_vector,const_int")
 {
   /* Memory is always valid.  */
-  if (memory_operand (op, mode))
+  if (any_memory_operand (op, mode))
 return 1;
 
   /* For floating-point, easy constants are valid.  */
-- 
1.8.3.1



cp: implementation of p1301 for C++

2019-07-20 Thread JeanHeyd Meneide
Dear GCC Community,

 This patch implements the recently accepted p1301: [[nodiscard("should
have a reason")]]. Aaron Ballman implemented it for Clang in
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20190715/280158.html
-- this is in preparation for a paper that will soon go to the C Committee
to keep feature-parity with C++ (the C2x draft already has attributes with
syntax exactly like C++).

Comments welcome: this is my first patch, and probably needs a lot of
help. This is also part of my Google Summer of Code training, to get used
to submitting and sending patches on the gcc-patches list.

Sincerely,
ThePhD



diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index e6452542bcc..3db90ec6c66 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,7 @@
+2019-07-20  ThePhD  
+
+ * c-family/c-lex.c: increase [[nodiscard]] feature macro value (final
value pending post-Cologne mailing)
+
 2019-07-20  Jakub Jelinek  

  * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_LOOP.

diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index 851fd704e5d..f2c0b62c95b 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -353,13 +353,14 @@ c_common_has_attribute (cpp_reader *pfile)
   else if (is_attribute_p ("deprecated", attr_name))
  result = 201309;
   else if (is_attribute_p ("maybe_unused", attr_name)
-   || is_attribute_p ("nodiscard", attr_name)
|| is_attribute_p ("fallthrough", attr_name))
  result = 201603;
   else if (is_attribute_p ("no_unique_address", attr_name)
|| is_attribute_p ("likely", attr_name)
|| is_attribute_p ("unlikely", attr_name))
  result = 201803;
+  else if (is_attribute_p ("nodiscard", attr_name))
+ result = 201907; /* placeholder until C++20 Post-Cologne Working Draft. */
   if (result)
  attr_name = NULL_TREE;
 }
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d645cdef147..9877b1af517 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,17 @@
+2019-07-20  ThePhD  
+
+ * escaped_string.h: New. Refactored out of tree.c to make more
+ broadly available (e.g. to parser.c, cvt.c).
+ * tree.c: Implement p1301 - nodiscard("should have a reason"))
+ Moved escaped_string class for working with attributes to
+ dedicated header.
+ Added C++2a nodiscard string message handling.
+ Increase nodiscard argument handling max_length from 0
+ to 1. (error C++2a gated)
+ * parser.c: add requirement that nodiscard only be seen
+ once in attribute-list (C++2a gated)
+ * cvt.c: add nodiscard message to output, if applicable
+
 2019-07-20  Jason Merrill  

  * cp-tree.h (ovl_iterator::using_p): A USING_DECL by itself was also

diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 23d2aabc483..aa4816f3a4f 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "convert.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "escaped_string.h"

 static tree convert_to_pointer_force (tree, tree, tsubst_flags_t);
 static tree build_type_conversion (tree, tree);
@@ -1029,19 +1030,29 @@ maybe_warn_nodiscard (tree expr, impl_conv_void
implicit)
   if (implicit != ICV_CAST && fn
   && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn)))
 {
-  auto_diagnostic_group d;
+  tree attr = DECL_ATTRIBUTES (fn);
+  escaped_string msg;
+  if (attr)
+ msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr;
+  bool has_msg = static_cast(msg);
+auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
-  "ignoring return value of %qD, "
-  "declared with attribute nodiscard", fn))
- inform (DECL_SOURCE_LOCATION (fn), "declared here");
+ "ignoring return value of %qD, "
+ "declared with attribute nodiscard%s%s", fn, (has_msg
? ": " : ""), (has_msg ? (const char*)msg : "")))
+inform (DECL_SOURCE_LOCATION (fn), "declared here");
 }
   else if (implicit != ICV_CAST
&& lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype)))
 {
+  tree attr = TYPE_ATTRIBUTES (rettype);
+  escaped_string msg;
+  if (attr)
+ msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr;
+  bool has_msg = static_cast(msg);
   auto_diagnostic_group d;
   if (warning_at (loc, OPT_Wunused_result,
-  "ignoring returned value of type %qT, "
-  "declared with attribute nodiscard", rettype))
+  "ignoring returned value of type %qT, "
+  "declared with attribute nodiscard%s%s", rettype,
(has_msg ? ": " : ""), (has_msg ? (const char*)msg : "")))
  {
   if (fn)
 inform (DECL_SOURCE_LOCATION (fn),
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 5c379aaf58d..d66d13615fc 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -26399,13 +26399,26 @@ cp_parser_check_std_attribute (tree attributes,
tree attribute)
 {
   tree name =

Re: [PATCH, Modula-2 (C/C++/D/F/Go/Jit)] (Register spec fn) (v2)

2019-07-20 Thread Matthias Klose
On 14.06.19 15:09, Gaius Mulley wrote:

I checked that gm2 cross compilers can be built. One minor nit: The man page is
installed without suffix and prefix.

gcc/gm2/Make-lang.in has

GM2_CROSS_NAME = `echo gm2|sed '$(program_transform_cross_name)'`

The program_transform_cross_name macro was removed in 2003, and doesn't do
anything.  The installation of the man page shouldn't be special-cased for a
cross build.

Matthias


Re: [PATCH,RFC,V4 4/5] CTF generation for a single compilation unit

2019-07-20 Thread Indu Bhagat
This patch was missing a stub from Makefile.in

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 5487377..0994f3b 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1257,6 +1257,8 @@ OBJS = \
cfgloopmanip.o \
cfgrtl.o \
ctfout.o \
+   ctfutils.o \
+   ctfcreate.o \
symtab.o \
cgraph.o \
cgraphbuild.o \

Sorry for inconvenience,
Indu

On Wed, Jul 17, 2019 at 4:58 PM Indu Bhagat  wrote:
>
> For each translation unit, a CTF container (ctf_container_t) is used to
> keep the CTF debug info.
>
> - ctfout.c hosts the compiler facing routines for CTF generation and emission.
> - ctfcreate.c contains the CTF format specific CTF creation routines.
> - ctfutils.c contains helper routines for CTF creation.
>
> [Changes from V3]
>- Bugfixes
>- Implementation for CTF function and object index sub-sections.
>- Skip types when CTF lacks representation for them.
>- CTF Compilation Unit name support (CU name).
>
>
> gcc/ChangeLog:
>
> * Makefile.in: Add new object files.
> * ctfcreate.c: New file.
> * ctfout.c (ctf_dtu_d_union_selector): New helper function for garbage
> collection of dtd_u union in ctf_dtdef_t.
> (ctfc_add_cuname): New function to add compilation unit name to CTF
> container.
> (ctf_dtdef_hash::hash): New function to generate hashkey for a CTF 
> type
> record.
> (hash_dtd_tree_decl): New function.
> (ctf_dtdef_hash::equal): Likewise.
> (is_ctf_base_type): Likewise.
> (get_cvr_quals_for_type): Likewise.
> (get_type_name_string): Likewise.
> (get_decl_name_string): Likewise.
> (ctf_type_exists): Likewise.
> (init_ctf_string_table): Likewise.
> (new_ctf_container): Allocate contents of CTF container.
> (delete_ctf_container): Cleanup contents of CTF container.
> (init_ctf_sections): Update code comments regarding LTO.
> (gen_ctf_base_type): New function.
> (gen_ctf_pointer_type): Likewise.
> (gen_ctf_array_type): Likewise.
> (gen_ctf_forward_type): Likewise.
> (gen_ctf_enum_const_list): Likewise.
> (gen_ctf_enum_type): Likewise.
> (gen_ctf_function_type): Likewise.
> (gen_ctf_cvrquals): Likewise.
> (gen_ctf_sou_type): Likewise.
> (gen_ctf_typedef): Likewise.
> (gen_ctf_variable): Likewise.
> (gen_ctf_function): Likewise.
> (gen_ctf_type): Likewise.
> (gen_ctf_bitfield_type_for_decl): Likewise.
> (gen_ctf_type_for_decl): Likewise.
> (ctf_preprocess_var): Likewise.
> (ctf_dvd_preprocess_cb): Likewise.
> (ctf_dtd_preprocess_cb): Likewise.
> (ctf_preprocess): Likewise.
> (ctf_asm_preamble): Likewise.
> (ctf_asm_stype): Likewise.
> (ctf_asm_type): Likewise.
> (ctf_asm_slice): Likewise.
> (ctf_asm_array): Likewise.
> (ctf_asm_varent): Likewise.
> (ctf_asm_sou_lmember): Likewise.
> (ctf_asm_sou_member): Likewise.
> (ctf_asm_enum_const): Likewise.
> (output_ctf_header): Output the CTF section if the CTF container is 
> not
> empty.
> (output_ctf_obj_info): New function.
> (output_ctf_func_info): Likewise.
> (output_ctf_objtidx): Likewise.
> (output_ctf_funcidx): Likewise.
> (output_ctf_vars): Likewise.
> (output_ctf_strs): Likewise.
> (output_asm_ctf_sou_fields): Likewise.
> (output_asm_ctf_enum_list): Likewise.
> (output_asm_ctf_vlen_bytes): Likewise.
> (output_asm_ctf_type): Likewise.
> (output_ctf_types): Likewise.
> (ctf_decl): Likewise.
> (ctf_early_finish): Trigger CTF emission.
> (ctf_early_global_decl): Invoke CTF generation function.
> (ctfout_c_finalize): Add cleanup of CTF container.
> * ctfout.h (typedef struct GTY): New data structures.
> (struct ctf_dtdef_hash): CTF type structure hasher.
> * ctfutils.c: New file.
>
> include/ChangeLog:
>
> * ctf.h: Sync with binutils.  Keep ctf_slice_t aligned.  Add CTF obj
> index and func index section.
>
> ---
>  gcc/ChangeLog |   70 +++
>  gcc/Makefile.in   |2 +
>  gcc/ctfcreate.c   |  531 
>  gcc/ctfout.c  | 1811 
> -
>  gcc/ctfout.h  |  317 +-
>  gcc/ctfutils.c|  198 ++
>  include/ChangeLog |5 +
>  include/ctf.h |   58 +-
>  8 files changed, 2942 insertions(+), 50 deletions(-)
>  create mode 100644 gcc/ctfcreate.c
>  create mode 100644 gcc/ctfutils.c
>
> diff --git a/gcc/ctfcreate.c b/gcc/ctfcreate.c
> new file mode 100644
> index 000..f14ee69
> --- /dev/null
> +++ b/gcc/ctfcreate.c
> @@ -0,0 +1,531 @@
> +/* Functions to create and update CTF from GCC.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +
> +This file is part 

Re: cp: implementation of p1301 for C++

2019-07-20 Thread Martin Sebor

On 7/20/19 11:29 AM, JeanHeyd Meneide wrote:

Dear GCC Community,

  This patch implements the recently accepted p1301: [[nodiscard("should
have a reason")]]. Aaron Ballman implemented it for Clang in
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20190715/280158.html
-- this is in preparation for a paper that will soon go to the C Committee
to keep feature-parity with C++ (the C2x draft already has attributes with
syntax exactly like C++).

 Comments welcome: this is my first patch, and probably needs a lot of
help. This is also part of my Google Summer of Code training, to get used
to submitting and sending patches on the gcc-patches list.


Just a few minor notes/suggestions.

...

--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
  #include "convert.h"
  #include "stringpool.h"
  #include "attribs.h"
+#include "escaped_string.h"

  static tree convert_to_pointer_force (tree, tree, tsubst_flags_t);
  static tree build_type_conversion (tree, tree);
@@ -1029,19 +1030,29 @@ maybe_warn_nodiscard (tree expr, impl_conv_void
implicit)
if (implicit != ICV_CAST && fn
&& lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn)))
  {
-  auto_diagnostic_group d;
+  tree attr = DECL_ATTRIBUTES (fn);
+  escaped_string msg;
+  if (attr)
+ msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr;
+  bool has_msg = static_cast(msg);
+auto_diagnostic_group d;
if (warning_at (loc, OPT_Wunused_result,
-  "ignoring return value of %qD, "
-  "declared with attribute nodiscard", fn))
- inform (DECL_SOURCE_LOCATION (fn), "declared here");
+ "ignoring return value of %qD, "
+ "declared with attribute nodiscard%s%s", fn, (has_msg
? ": " : ""), (has_msg ? (const char*)msg : "")))
+inform (DECL_SOURCE_LOCATION (fn), "declared here");


While making changes here, would you mind adding quotes around
nodiscard (i.e., %).  Should the text included in
the attribute also be similarly quoted so that it's highlighted
in the diagnostic?


  }
else if (implicit != ICV_CAST
 && lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype)))
  {
+  tree attr = TYPE_ATTRIBUTES (rettype);
+  escaped_string msg;
+  if (attr)
+ msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr;
+  bool has_msg = static_cast(msg);
auto_diagnostic_group d;
if (warning_at (loc, OPT_Wunused_result,
-  "ignoring returned value of type %qT, "
-  "declared with attribute nodiscard", rettype))
+  "ignoring returned value of type %qT, "
+  "declared with attribute nodiscard%s%s", rettype,


Also here.


(has_msg ? ": " : ""), (has_msg ? (const char*)msg : "")))
   {
if (fn)
  inform (DECL_SOURCE_LOCATION (fn),

...

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 37e24a1669c..8c2d056f3eb 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -4356,9 +4356,27 @@ zero_init_p (const_tree t)
 warn_unused_result attribute.  */

  static tree
-handle_nodiscard_attribute (tree *node, tree name, tree /*args*/,
+handle_nodiscard_attribute (tree *node, tree name, tree args,
  int /*flags*/, bool *no_add_attrs)
  {
+  if (!args)
+*no_add_attrs = true;
+  else if (cxx_dialect >= cxx2a)
+{
+  if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
+{
+  error ("nodiscard attribute argument must be a string");


And also here; to reduce the number of format strings that have to
be translated it's best to use:

  error ("%qE attribute argument must be a string constant", name);


+  *no_add_attrs = true;
+}
+}
+  else
+{
+  if (!*no_add_attrs)
+{
+  error("nodiscard attribute does not take any arguments: use flag
%<-std=c2a%> or better to compile your code");


Also here.  Rather than a colon I think the dominant style is to
use a semicolon but I would suggest:

  error ("%E attribute with an argument only available with "
 "%<-std=c++2a%> or %<-std=gnu++2a%>");

in keeping with other messages like it (see gcc/po/gcc.pot for
examples).  (I assume the option to enable the C++ 2a dialect
is -std=c++2a, not -std=c2a.)


+++ b/gcc/escaped_string.h
@@ -0,0 +1,41 @@

...

+/* A class to handle converting a string that might contain
+   control characters, (eg newline, form-feed, etc), into one
+   in which contains escape sequences instead.  */
+
+class escaped_string
+{
+ public:
+  escaped_string () { m_owned = false; m_str = NULL; };
+  ~escaped_string () { if (m_owned) free (m_str); }
+  operator const char *() const { return (const char *) m_str; }
+  void escape (const char *);
+ private:
+  char *m_str;
+  bool  m_owned;
+};


Since the class isn't safe to copy/assign and it's being moved
to a header, could you please make its copy ctor and assignment
operator private to prevent its objects from accide

Re: cp: implementation of p1301 for C++

2019-07-20 Thread Segher Boessenkool
On Sat, Jul 20, 2019 at 03:48:40PM -0600, Martin Sebor wrote:
> On 7/20/19 11:29 AM, JeanHeyd Meneide wrote:
> >+[[nodiscard(123)]] int check1 (void); /* { dg-error "nodiscard attribute
> >argument.*must be a string" } */
> 
> Using .* might be safe in a test with a single line of output but
> not in other tests where it might consume newlines.  It's best to

Just start the string with  (?n)  and all is good.


Segher


Re: [PATCH v3 3/3] PR80791 Consider doloop cmp use in ivopts

2019-07-20 Thread Bin.Cheng
On Wed, Jun 19, 2019 at 7:47 PM Kewen.Lin  wrote:
>
> Hi all,
>
> This is the following patch after 
> https://gcc.gnu.org/ml/gcc-patches/2019-06/msg00910.html
>
> Main steps:
>   1) Identify the doloop cmp type iv use and record its bind_cand (explain it 
> later).
>   2) Set zero cost for pairs between this use and any iv cand.
>   3) IV cand set selecting algorithm runs as usual.
>   4) Fix up the selected iv cand for doloop use if need.
>
> It only focuses on the targets like Power which has specific count register.
> target hook have_count_reg_decr_p is proposed for it.
>
> Some notes:
>
> *) Why we need zero cost?  How about just decrease the cost for the pair
>between doloop use and its original iv cand?  How about just decrease
>the cost for the pair between doloop use and one selected iv cand?
>
>Since some target supports hardware count register for decrement and
>branch, it doesn't need the general instruction sequence for decr, cmp and
>branch in general registers.  The cost of moving count register to GPR
>is generally high, so it's standalone and can't be shared with other iv
>uses.  It means IVOPTs can take doloop use as invisible (zero cost).
>
>Let's take a look at PR80791 for example.
>
> original biv (cand 4)  use derived iv (cand 6)
>  generic use:   4  0
>  comp use (doloop use): 0 infinite
>
> For iv cost, original biv has cost 4 while use derived iv has cost 5.
> When IVOPTs considers doloop use, the optimal cost is 8 (original biv
> iv cost 4 + use cost 4).  Unfortunately it's not actually optimal, since
> later doloop transformation updates loop closing by count register,
> original biv (and its update) won't be needed in loop closing any more.
> The generic use become the only use for original biv.  That means, if we
> know the doloop will perform later, we shouldn't consider the doloop use
> when determining IV set.  If we don't consider it, the algorithm will
> choose iv cand 6 with total cost 5 (iv cost 5 + use cost 0).
>
> From the above, we can see that to decrease the cost for the pair between
> doloop use and original biv doesn't work.  Meanwhile it's hard to predict
> one good iv cand in final optimal set here and pre-update the cost
> between it and doloop use.  The analysis would be heavy and imperfect.
>
> *) Why we need bind_cand?
>
> As above, we assign zero cost for pairs between doloop use and each iv
> cand.  It's possible that doloop use gets assigned one iv cand which is
> invalid to be used during later rewrite.  Then we have to fix it up with 
> iv
> cand originally used for it.  It's fine whatever this iv cand exists in
> final iv cand set or not, even if it's not in the set, it will be
> eliminated in doloop transformation.
>
> By the way, I was thinking whether we can replace the hook 
> have_count_reg_decr_p
> with flag_branch_on_count_reg.  As the description of the "no-" option, 
> "Disable
> the optimization pass that scans for opportunities to use 'decrement and 
> branch'
> instructions on a count register instead of instruction sequences that 
> decrement
> a register, compare it against zero, and then branch based upon the result.", 
> it
> implicitly says it has count register support.  But I noticed that the gate of
> doloop_optimize checks this flag, as what I got from the previous 
> discussions, some
> targets which can perform doloop_optimize don't have specific count register, 
> so it
> sounds we can't make use of the flag, is it correct?
>
> Bootstrapped on powerpcle, also ran regression testing on powerpcle, got one 
> failure
> which is exposed by this patch and the root cause is duplicate of PR62147.
> case is gcc.target/powerpc/20050830-1.c
>
> Is it OK for trunk?
Sorry for the delaying.

I am not in favor of the approach very much.  When rewriting the pass
last time, we tried to reuse as much code as possible between cost
computation and iv_use rewriting.  we also followed guideline when
finite cost computed for cand/use pair, the use should be rewritten
using the cand successfully.  However, the patch adjust infinite cost
to zero cost causing cand can't be used to rewrite iv_use selected,
this is a backward step IMHO.

I am not sure if this is only useful for doloop cases, or for general cases?

Comment mentioned the point is to give more chances to consider other
IV cands instead of BIV.  If current algorithm relies on zeroing cost
of impossible cand/use pair to select optimal result, I suspect it's a
bug which should be fixed in candidate selection algorithm.  Do you
have a test case showing the issue? We should fix it as a standalone
problem, while the approach is covering the problem and not that
sound.

However, I think the patch can be changed that only finite cost should
be adjusted to zero.  Thus guarantee any cand selected is vali