[PATCH 5/7] jit,docs: use list-table instead of fixed table

2022-07-25 Thread Martin Liska
Use rather list-table that is easible to maintainer and one
does not have to wrap lines. Moreover, it provides great
attribute :widths: that correctly works (tested for HTML and PDF).

gcc/jit/ChangeLog:

* docs/cp/intro/tutorial04.rst: Use list-table.
* docs/intro/tutorial04.rst: Likewise.
* docs/intro/tutorial05.rst: Likewise.
* docs/topics/compilation.rst: Likewise.
* docs/topics/expressions.rst: Likewise.
* docs/topics/types.rst: Likewise.
---
 gcc/jit/docs/cp/intro/tutorial04.rst |  73 --
 gcc/jit/docs/intro/tutorial04.rst|  73 --
 gcc/jit/docs/intro/tutorial05.rst|  37 +
 gcc/jit/docs/topics/compilation.rst  |  22 --
 gcc/jit/docs/topics/expressions.rst  |  97 ++-
 gcc/jit/docs/topics/types.rst| 111 +--
 6 files changed, 270 insertions(+), 143 deletions(-)

diff --git a/gcc/jit/docs/cp/intro/tutorial04.rst 
b/gcc/jit/docs/cp/intro/tutorial04.rst
index 45198ce3d7a..66dcce903c6 100644
--- a/gcc/jit/docs/cp/intro/tutorial04.rst
+++ b/gcc/jit/docs/cp/intro/tutorial04.rst
@@ -50,30 +50,55 @@ Naturally, a real interpreter would be much more 
complicated that this.
 
 The following operations are supported:
 
-==  === ==
-Operation  Meaning  Old Stack   New Stack
-==  === ==
-DUPDuplicate top of stack.  ``[..., x]````[..., x, x]``
-ROTSwap top two elements``[..., x, y]`` ``[..., y, x]``
-   of stack.
-BINARY_ADD Add the top two elements ``[..., x, y]`` ``[..., 
(x+y)]``
-   on the stack.
-BINARY_SUBTRACTLikewise, but subtract.  ``[..., x, y]`` ``[..., 
(x-y)]``
-BINARY_MULTLikewise, but multiply.  ``[..., x, y]`` ``[..., 
(x*y)]``
-BINARY_COMPARE_LT  Compare the top two  ``[..., x, y]`` ``[..., 
(x``  ``idx += 1``
-``<``  ``idx -= 1``
-``+``  ``data[idx] += 1``
-``-``  ``data[idx] -= 1``
-``.``  ``output (data[idx])``
-``,``  ``data[idx] = input ()``
-``[``  loop until ``data[idx] == 0``
-``]``  end of loop
-Anything else  ignored
-== =
+.. list-table::
+   :header-rows: 1
+
+   * - Character
+ - Meaning
+
+   * - ``>``
+ - ``idx += 1``
+   * - ``<``
+ - ``idx -= 1``
+   * - ``+``
+ - ``data[idx] += 1``
+   * - ``-``
+ - ``data[idx] -= 1``
+   * - ``.``
+ - ``output (data[idx])``
+   * - ``,``
+ - ``data[idx] = input ()``
+   * - ``[``
+ - loop until ``data[idx] == 0``
+   * - ``]``
+ - end of loop
+   * - Anything else
+ - ignored
 
 Unlike the previous example, we'll implement an ahead-of-time compiler,
 which reads ``.bf`` scripts and outputs executables (though it would
diff --git a/gcc/jit/docs/topics/compilation.rst 
b/gcc/jit/docs/topics/compilation.rst
index 91b9c2533cf..adcde8d8eb9 100644
--- a/gcc/jit/docs/topics/compilation.rst
+++ b/gcc/jit/docs/topics/compilation.rst
@@ -169,14 +169,20 @@ For linking in object files, use 
:c:func:`gcc_jit_context_add_driver_option`.
 
 The available kinds of output are:
 
-==  ==
-Output kind Typical suffix
-==  ==
-:c:macro:`GCC_JIT_OUTPUT_KIND_ASSEMBLER`.s
-:c:macro:`GCC_JIT_OUTPUT_KIND_OBJECT_FILE`  .o
-:c:macro:`GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY`  .so or .dll
-:c:macro:`GCC_JIT_OUTPUT_KIND_EXECUTABLE`   None, or .exe
-==  ==
+.. list-table::
+   :header-rows: 1
+
+   * - Output kind
+ - Typical suffix
+
+   * - :c:macro:`GCC_JIT_OUTPUT_KIND_ASSEMBLER`
+ - .s
+   * - :c:macro:`GCC_JIT_OUTPUT_KIND_OBJECT_FILE`
+ - .o
+   * - :c:macro:`GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY`
+ - .so or .dll
+   * - :c:macro:`GCC_JIT_OUTPUT_KIND_EXECUTABLE`
+ - None, or .exe
 
 .. c:macro:: GCC_JIT_OUTPUT_KIND_ASSEMBLER
 
diff --git a/gcc/jit/docs/topics/expressions.rst 
b/gcc/jit/docs/topics/expressions.rst
index 00e2ec8cfeb..ff1eec800ce 100644
--- a/gcc/jit/docs/topics/expressions.rst
+++ b/gcc/jit/docs/topics/expressions.rst
@@ -313,14 +313,20 @@ Unary Operations
 
 The available unary operations are:
 
-==  
-Unary Operation C equivalent
-==  
-:c:macro:`GCC_JIT_UNARY_OP_MINUS`   `-(EXPR)`
-:c:macro:`GCC_JIT_UNARY_OP_BITWISE_NEGATE`  `~(EXPR)`
-:c:macro:`GCC_JIT_UNARY_OP_LOGICAL_NEGATE`  `!(EXPR)`
-:c:macro:`GCC_JIT_UNARY_OP_ABS` 

[PATCH 3/7] jit,docs: various fixes

2022-07-25 Thread Martin Liska
gcc/jit/ChangeLog:

* docs/cp/intro/tutorial02.rst: Use proper reference.
* docs/cp/topics/contexts.rst: Likewise.
* docs/cp/topics/functions.rst: Put `class` directive before a
function as it is not allowed declaring a class in a fn.
* docs/cp/topics/types.rst: Add template keyword.
* docs/examples/tut04-toyvm/toyvm.c (toyvm_function_compile):
Add removed comment used for code snippet ending detection.
* docs/intro/tutorial04.rst: Fix to match the real comment.
---
 gcc/jit/docs/cp/intro/tutorial02.rst  |  2 +-
 gcc/jit/docs/cp/topics/contexts.rst   |  2 +-
 gcc/jit/docs/cp/topics/functions.rst  | 46 +++
 gcc/jit/docs/cp/topics/types.rst  |  2 +-
 gcc/jit/docs/examples/tut04-toyvm/toyvm.c |  1 +
 gcc/jit/docs/intro/tutorial04.rst |  2 +-
 6 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/gcc/jit/docs/cp/intro/tutorial02.rst 
b/gcc/jit/docs/cp/intro/tutorial02.rst
index 2064f8e4dd9..55675cc7398 100644
--- a/gcc/jit/docs/cp/intro/tutorial02.rst
+++ b/gcc/jit/docs/cp/intro/tutorial02.rst
@@ -121,7 +121,7 @@ in this case just one:
   params.push_back (param_i);
 
 Now we can create the function, using
-:c:func:`gccjit::context::new_function`:
+:cpp:func:`gccjit::context::new_function`:
 
 .. code-block:: c++
 
diff --git a/gcc/jit/docs/cp/topics/contexts.rst 
b/gcc/jit/docs/cp/topics/contexts.rst
index e5bccfb807d..f60f2102b3e 100644
--- a/gcc/jit/docs/cp/topics/contexts.rst
+++ b/gcc/jit/docs/cp/topics/contexts.rst
@@ -141,7 +141,7 @@ Debugging
If "update_locations" is true, then also set up :class:`gccjit::location`
information throughout the context, pointing at the dump file as if it
were a source file.  This may be of use in conjunction with
-   :c:macro:`GCCJIT::BOOL_OPTION_DEBUGINFO` to allow stepping through the
+   :c:macro:`GCC_JIT_BOOL_OPTION_DEBUGINFO` to allow stepping through the
code in a debugger.
 
 .. function:: void\
diff --git a/gcc/jit/docs/cp/topics/functions.rst 
b/gcc/jit/docs/cp/topics/functions.rst
index 0e266abc70c..4e325ac3fef 100644
--- a/gcc/jit/docs/cp/topics/functions.rst
+++ b/gcc/jit/docs/cp/topics/functions.rst
@@ -243,6 +243,29 @@ Statements
 
   return;
 
+.. class:: gccjit::case_
+
+   A `gccjit::case_` represents a case within a switch statement, and
+   is created within a particular :class:`gccjit::context` using
+   :func:`gccjit::context::new_case`.  It is a subclass of
+   :class:`gccjit::object`.
+
+   Each case expresses a multivalued range of integer values.  You
+   can express single-valued cases by passing in the same value for
+   both `min_value` and `max_value`.
+
+.. function:: gccjit::case_ *\
+   gccjit::context::new_case (gccjit::rvalue min_value,\
+  gccjit::rvalue max_value,\
+  gccjit::block dest_block)
+
+Create a new gccjit::case for use in a switch statement.
+`min_value` and `max_value` must be constants of an integer type,
+which must match that of the expression of the switch statement.
+
+`dest_block` must be within the same function as the switch
+statement.
+
 .. function:: void\
   gccjit::block::end_with_switch (gccjit::rvalue expr,\
   gccjit::block default_block,\
@@ -292,29 +315,6 @@ Statements
 
   #ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS
 
-   .. class:: gccjit::case_
-
-   A `gccjit::case_` represents a case within a switch statement, and
-   is created within a particular :class:`gccjit::context` using
-   :func:`gccjit::context::new_case`.  It is a subclass of
-   :class:`gccjit::object`.
-
-   Each case expresses a multivalued range of integer values.  You
-   can express single-valued cases by passing in the same value for
-   both `min_value` and `max_value`.
-
-   .. function:: gccjit::case_ *\
- gccjit::context::new_case (gccjit::rvalue min_value,\
-gccjit::rvalue max_value,\
-gccjit::block dest_block)
-
-  Create a new gccjit::case for use in a switch statement.
-  `min_value` and `max_value` must be constants of an integer type,
-  which must match that of the expression of the switch statement.
-
-  `dest_block` must be within the same function as the switch
-  statement.
-
Here's an example of creating a switch statement:
 
  .. literalinclude:: ../../../../testsuite/jit.dg/test-switch.cc
diff --git a/gcc/jit/docs/cp/topics/types.rst b/gcc/jit/docs/cp/topics/types.rst
index c695ceb3098..5d50a39b9d0 100644
--- a/gcc/jit/docs/cp/topics/types.rst
+++ b/gcc/jit/docs/cp/topics/types.rst
@@ -65,7 +65,7 @@ Standard types
 
Access the integer type of the given size.
 
-.. function:: gccjit::type \
+.. function:: template gccjit::type \
   gccjit::context::get_int_type  ()
 

[PATCH 4/7] jit,docs: compact function declarations

2022-07-25 Thread Martin Liska
gcc/jit/ChangeLog:

* docs/cp/topics/expressions.rst: Compact so that the generated
output is also more compact.
---
 gcc/jit/docs/cp/topics/expressions.rst | 42 +-
 1 file changed, 14 insertions(+), 28 deletions(-)

diff --git a/gcc/jit/docs/cp/topics/expressions.rst 
b/gcc/jit/docs/cp/topics/expressions.rst
index 003dbce8991..dec5b477811 100644
--- a/gcc/jit/docs/cp/topics/expressions.rst
+++ b/gcc/jit/docs/cp/topics/expressions.rst
@@ -236,48 +236,39 @@ operation:
   gccjit::context::new_plus (gccjit::type result_type, \
  gccjit::rvalue a, gccjit::rvalue b, \
  gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_minus (gccjit::type result_type, \
   gccjit::rvalue a, gccjit::rvalue b, \
   gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_mult (gccjit::type result_type, \
  gccjit::rvalue a, gccjit::rvalue b, \
  gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_divide (gccjit::type result_type, \
gccjit::rvalue a, gccjit::rvalue b, 
\
gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_modulo (gccjit::type result_type, \
gccjit::rvalue a, gccjit::rvalue b, 
\
gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_bitwise_and (gccjit::type result_type, \
 gccjit::rvalue a, 
gccjit::rvalue b, \
 gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_bitwise_xor (gccjit::type result_type, \
 gccjit::rvalue a, 
gccjit::rvalue b, \
 gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_bitwise_or (gccjit::type result_type, \
gccjit::rvalue a, 
gccjit::rvalue b, \
gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_logical_and (gccjit::type result_type, \
 gccjit::rvalue a, 
gccjit::rvalue b, \
 gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_logical_or (gccjit::type result_type, \
gccjit::rvalue a, 
gccjit::rvalue b, \
gccjit::location loc)
@@ -375,24 +366,19 @@ operation:
 .. function:: gccjit::rvalue \
   gccjit::context::new_eq (gccjit::rvalue a, gccjit::rvalue b, \
gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_ne (gccjit::rvalue a, gccjit::rvalue b, \
gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_lt (gccjit::rvalue a, gccjit::rvalue b, \
gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_le (gccjit::rvalue a, gccjit::rvalue b, \
gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_gt (gccjit::rvalue a, gccjit::rvalue b, \
gccjit::location loc)
-
-.. function:: gccjit::rvalue \
+  gccjit::rvalue \
   gccjit::context::new_ge (gccjit::rvalue a, gccjit::rvalue b, \
gccjit::location loc)
 
-- 
2.37.1




[PATCH 1/7] jit,docs: use enum directive for enumeral types

2022-07-25 Thread Martin Liska
gcc/jit/ChangeLog:

* docs/conf.py: Add needs_sphinx = '3.0' where c:type was added.
* docs/index.rst: Remove note about it.
* docs/topics/compilation.rst: Use enum directive and reference.
* docs/topics/contexts.rst: Likewise.
* docs/topics/expressions.rst: Likewise.
* docs/topics/functions.rst: Likewise.
---
 gcc/jit/docs/conf.py|  3 +++
 gcc/jit/docs/index.rst  |  7 ---
 gcc/jit/docs/topics/compilation.rst |  4 ++--
 gcc/jit/docs/topics/contexts.rst|  6 +++---
 gcc/jit/docs/topics/expressions.rst | 10 +-
 gcc/jit/docs/topics/functions.rst   |  2 +-
 6 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/gcc/jit/docs/conf.py b/gcc/jit/docs/conf.py
index 00f0e9887dd..062232ae280 100644
--- a/gcc/jit/docs/conf.py
+++ b/gcc/jit/docs/conf.py
@@ -39,6 +39,9 @@ source_suffix = '.rst'
 # The master toctree document.
 master_doc = 'index'
 
+# c:type directive is supported since 3.0
+needs_sphinx = '3.0'
+
 # General information about the project.
 project = u'libgccjit'
 copyright = u'2014-2022 Free Software Foundation, Inc.'
diff --git a/gcc/jit/docs/index.rst b/gcc/jit/docs/index.rst
index 3aff17d7a60..21c3140e238 100644
--- a/gcc/jit/docs/index.rst
+++ b/gcc/jit/docs/index.rst
@@ -45,10 +45,3 @@ Indices and tables
 * :ref:`genindex`
 * :ref:`modindex`
 * :ref:`search`
-
-.. Some notes:
-
-   The Sphinx C domain appears to lack explicit support for enum values,
-   so I've been using :c:macro: for them.
-
-   See https://sphinx-doc.org/domains.html#the-c-domain
diff --git a/gcc/jit/docs/topics/compilation.rst 
b/gcc/jit/docs/topics/compilation.rst
index 9b1eed2dede..c5fa6eb0faf 100644
--- a/gcc/jit/docs/topics/compilation.rst
+++ b/gcc/jit/docs/topics/compilation.rst
@@ -158,14 +158,14 @@ For linking in object files, use 
:c:func:`gcc_jit_context_add_driver_option`.
 
 :c:func:`gcc_jit_context_compile_to_file` ignores the suffix of
 ``output_path``, and insteads uses the given
-:c:type:`enum gcc_jit_output_kind` to decide what to do.
+:c:enum:`gcc_jit_output_kind` to decide what to do.
 
 .. note::
 
This is different from the ``gcc`` program, which does make use of the
suffix of the output file when determining what to do.
 
-.. type:: enum gcc_jit_output_kind
+.. enum:: gcc_jit_output_kind
 
 The available kinds of output are:
 
diff --git a/gcc/jit/docs/topics/contexts.rst b/gcc/jit/docs/topics/contexts.rst
index dfbe968e127..205b5f3dcf5 100644
--- a/gcc/jit/docs/topics/contexts.rst
+++ b/gcc/jit/docs/topics/contexts.rst
@@ -311,7 +311,7 @@ String Options
 
Set a string option of the context.
 
-   .. type:: enum gcc_jit_str_option
+   .. enum:: gcc_jit_str_option
 
The parameter ``value`` can be NULL.   If non-NULL, the call takes a
copy of the underlying string, so it is valid to pass in a pointer to
@@ -334,7 +334,7 @@ Boolean options
   Set a boolean option of the context.
   Zero is "false" (the default), non-zero is "true".
 
-  .. type:: enum gcc_jit_bool_option
+  .. enum:: gcc_jit_bool_option
 
   .. macro:: GCC_JIT_BOOL_OPTION_DEBUGINFO
 
@@ -513,7 +513,7 @@ Integer options
 
   Set an integer option of the context.
 
-  .. type:: enum gcc_jit_int_option
+  .. enum:: gcc_jit_int_option
 
   There is just one integer option specified this way:
 
diff --git a/gcc/jit/docs/topics/expressions.rst 
b/gcc/jit/docs/topics/expressions.rst
index 91ee8a9c74a..49b7e14ae2b 100644
--- a/gcc/jit/docs/topics/expressions.rst
+++ b/gcc/jit/docs/topics/expressions.rst
@@ -309,7 +309,7 @@ Unary Operations
 
The parameter ``result_type`` must be a numeric type.
 
-.. type:: enum gcc_jit_unary_op
+.. enum:: gcc_jit_unary_op
 
 The available unary operations are:
 
@@ -376,7 +376,7 @@ Binary Operations
 
The parameter ``result_type`` must be a numeric type.
 
-.. type:: enum gcc_jit_binary_op
+.. enum:: gcc_jit_binary_op
 
 The available binary operations are:
 
@@ -534,7 +534,7 @@ Comparisons
 
Build a boolean rvalue out of the comparison of two other rvalues.
 
-.. type:: enum gcc_jit_comparison
+.. enum:: gcc_jit_comparison
 
 ===  
 Comparison   C equivalent
@@ -711,7 +711,7 @@ where the rvalue is computed by reading from the storage 
area.
 
The "model" parameter determines the thread-local storage model of the 
"lvalue":
 
-   .. type:: enum gcc_jit_tls_model
+   .. enum:: gcc_jit_tls_model
 
.. c:macro:: GCC_JIT_TLS_MODEL_NONE
 
@@ -841,7 +841,7 @@ Global variables
The "kind" parameter determines the visibility of the "global" outside
of the :c:type:`gcc_jit_result`:
 
-   .. type:: enum gcc_jit_global_kind
+   .. enum:: gcc_jit_global_kind
 
.. c:macro:: GCC_JIT_GLOBAL_EXPORTED
 
diff --git a/gcc/jit/docs/topics/functions.rst 
b/gcc/jit/docs/topics/functions.rst
index 0845fe0f7d3..d6d4fe90834 100644
--- a/gcc/jit/docs/topics/functions.rst
+++ b/gcc/jit/docs/topics/functions.rst
@@ 

[PATCH 2/7] jit, docs: replace c:type:`int_type` with :expr:`int_type`

2022-07-25 Thread Martin Liska
Use expression that work fine for basic type.

gcc/jit/ChangeLog:

* docs/cp/topics/expressions.rst: Use :expr: for basic types.
* docs/topics/compilation.rst: Likewise.
* docs/topics/expressions.rst: Likewise.
* docs/topics/function-pointers.rst: Likewise.
---
 gcc/jit/docs/cp/topics/expressions.rst| 6 +++---
 gcc/jit/docs/topics/compilation.rst   | 4 ++--
 gcc/jit/docs/topics/expressions.rst   | 6 +++---
 gcc/jit/docs/topics/function-pointers.rst | 2 +-
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/gcc/jit/docs/cp/topics/expressions.rst 
b/gcc/jit/docs/cp/topics/expressions.rst
index 239e004371e..003dbce8991 100644
--- a/gcc/jit/docs/cp/topics/expressions.rst
+++ b/gcc/jit/docs/cp/topics/expressions.rst
@@ -57,14 +57,14 @@ Simple expressions
int value) const
 
Given a numeric type (integer or floating point), build an rvalue for
-   the given constant :c:type:`int` value.
+   the given constant :expr:`int` value.
 
 .. function:: gccjit::rvalue \
   gccjit::context::new_rvalue (gccjit::type numeric_type, \
long value) const
 
Given a numeric type (integer or floating point), build an rvalue for
-   the given constant :c:type:`long` value.
+   the given constant :expr:`long` value.
 
 .. function::  gccjit::rvalue \
gccjit::context::zero (gccjit::type numeric_type) const
@@ -91,7 +91,7 @@ Simple expressions
 double value) const
 
Given a numeric type (integer or floating point), build an rvalue for
-   the given constant :c:type:`double` value.
+   the given constant :expr:`double` value.
 
 .. function:: gccjit::rvalue \
   gccjit::context::new_rvalue (gccjit::type pointer_type, \
diff --git a/gcc/jit/docs/topics/compilation.rst 
b/gcc/jit/docs/topics/compilation.rst
index c5fa6eb0faf..91b9c2533cf 100644
--- a/gcc/jit/docs/topics/compilation.rst
+++ b/gcc/jit/docs/topics/compilation.rst
@@ -98,8 +98,8 @@ In-memory compilation
If the global is found, the result will need to be cast to a
pointer of the correct type before it can be called.
 
-   This is a *pointer* to the global, so e.g. for an :c:type:`int` this is
-   an :c:type:`int *`.
+   This is a *pointer* to the global, so e.g. for an :expr:`int` this is
+   an :expr:`int *`.
 
For example, given an ``int foo;`` created this way:
 
diff --git a/gcc/jit/docs/topics/expressions.rst 
b/gcc/jit/docs/topics/expressions.rst
index 49b7e14ae2b..00e2ec8cfeb 100644
--- a/gcc/jit/docs/topics/expressions.rst
+++ b/gcc/jit/docs/topics/expressions.rst
@@ -60,7 +60,7 @@ Simple expressions
int value)
 
Given a numeric type (integer or floating point), build an rvalue for
-   the given constant :c:type:`int` value.
+   the given constant :expr:`int` value.
 
 .. function:: gcc_jit_rvalue *\
   gcc_jit_context_new_rvalue_from_long (gcc_jit_context *ctxt, \
@@ -68,7 +68,7 @@ Simple expressions
 long value)
 
Given a numeric type (integer or floating point), build an rvalue for
-   the given constant :c:type:`long` value.
+   the given constant :expr:`long` value.
 
 .. function::  gcc_jit_rvalue *gcc_jit_context_zero (gcc_jit_context *ctxt, \
  gcc_jit_type 
*numeric_type)
@@ -96,7 +96,7 @@ Simple expressions
double value)
 
Given a numeric type (integer or floating point), build an rvalue for
-   the given constant :c:type:`double` value.
+   the given constant :expr:`double` value.
 
 .. function:: gcc_jit_rvalue *\
   gcc_jit_context_new_rvalue_from_ptr (gcc_jit_context *ctxt, \
diff --git a/gcc/jit/docs/topics/function-pointers.rst 
b/gcc/jit/docs/topics/function-pointers.rst
index e6f9970a7a7..dde49215853 100644
--- a/gcc/jit/docs/topics/function-pointers.rst
+++ b/gcc/jit/docs/topics/function-pointers.rst
@@ -48,7 +48,7 @@ to it in :c:type:`gcc_jit_rvalue` form using
 type obtained using :c:func:`gcc_jit_context_new_function_ptr_type`.
 
 Here's an example of creating a function pointer type corresponding to C's
-:c:type:`void (*) (int, int, int)`:
+:expr:`void (*) (int, int, int)`:
 
 .. code-block:: c
 
-- 
2.37.1




[PATCH 6/7] jit,docs: use :expr:`type *` for pointers to a type

2022-07-25 Thread Martin Liska
gcc/jit/ChangeLog:

* docs/cp/intro/tutorial02.rst: Use :expr:`type *` for pointers to a 
type
* docs/cp/topics/asm.rst: Likewise.
* docs/cp/topics/contexts.rst: Likewise.
* docs/cp/topics/expressions.rst: Likewise.
* docs/cp/topics/functions.rst: Likewise.
* docs/cp/topics/objects.rst: Likewise.
* docs/intro/tutorial02.rst: Likewise.
* docs/intro/tutorial03.rst: Likewise.
* docs/intro/tutorial04.rst: Likewise.
* docs/intro/tutorial05.rst: Likewise.
* docs/topics/compilation.rst: Likewise.
* docs/topics/contexts.rst: Likewise.
* docs/topics/objects.rst: Likewise.
---
 gcc/jit/docs/cp/intro/tutorial02.rst   |  4 ++--
 gcc/jit/docs/cp/topics/asm.rst |  2 +-
 gcc/jit/docs/cp/topics/contexts.rst|  6 +++---
 gcc/jit/docs/cp/topics/expressions.rst |  4 ++--
 gcc/jit/docs/cp/topics/functions.rst   |  2 +-
 gcc/jit/docs/cp/topics/objects.rst |  2 +-
 gcc/jit/docs/intro/tutorial02.rst  | 16 +++
 gcc/jit/docs/intro/tutorial03.rst  | 28 +-
 gcc/jit/docs/intro/tutorial04.rst  |  2 +-
 gcc/jit/docs/intro/tutorial05.rst  |  4 ++--
 gcc/jit/docs/topics/compilation.rst|  8 
 gcc/jit/docs/topics/contexts.rst   |  6 +++---
 gcc/jit/docs/topics/objects.rst|  6 +++---
 13 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/gcc/jit/docs/cp/intro/tutorial02.rst 
b/gcc/jit/docs/cp/intro/tutorial02.rst
index 55675cc7398..9f9a7f3858e 100644
--- a/gcc/jit/docs/cp/intro/tutorial02.rst
+++ b/gcc/jit/docs/cp/intro/tutorial02.rst
@@ -39,7 +39,7 @@ First we need to include the relevant header:
 
 All state associated with compilation is associated with a
 :type:`gccjit::context`, which is a thin C++ wrapper around the C API's
-:c:type:`gcc_jit_context *`.
+:c:expr:`gcc_jit_context *`.
 
 Create one using :func:`gccjit::context::acquire`:
 
@@ -194,7 +194,7 @@ OK, we've populated the context.  We can now compile it 
using
gcc_jit_result *result;
result = ctxt.compile ();
 
-and get a :c:type:`gcc_jit_result *`.
+and get a :c:expr:`gcc_jit_result *`.
 
 We can now use :c:func:`gcc_jit_result_get_code` to look up a specific
 machine code routine within the result, in this case, the function we
diff --git a/gcc/jit/docs/cp/topics/asm.rst b/gcc/jit/docs/cp/topics/asm.rst
index f7e4e952b10..0d63da3d59e 100644
--- a/gcc/jit/docs/cp/topics/asm.rst
+++ b/gcc/jit/docs/cp/topics/asm.rst
@@ -43,7 +43,7 @@ Adding assembler instructions within a function
to outputs.
 
:class:`gccjit::extended_asm` is a subclass of :class:`gccjit::object`.
-   It is a thin wrapper around the C API's :c:type:`gcc_jit_extended_asm *`.
+   It is a thin wrapper around the C API's :c:expr:`gcc_jit_extended_asm *`.
 
To avoid having an API entrypoint with a very large number of
parameters, an extended ``asm`` statement is made in stages:
diff --git a/gcc/jit/docs/cp/topics/contexts.rst 
b/gcc/jit/docs/cp/topics/contexts.rst
index f60f2102b3e..2f2456a9c0d 100644
--- a/gcc/jit/docs/cp/topics/contexts.rst
+++ b/gcc/jit/docs/cp/topics/contexts.rst
@@ -29,9 +29,9 @@ compilation.
 
 You can set up options on it, and add types, functions and code.
 Invoking :func:`gccjit::context::compile` on it gives you a
-:c:type:`gcc_jit_result *`.
+:c:expr:`gcc_jit_result *`.
 
-It is a thin wrapper around the C API's :c:type:`gcc_jit_context *`.
+It is a thin wrapper around the C API's :c:expr:`gcc_jit_context *`.
 
 Lifetime-management
 ---
@@ -48,7 +48,7 @@ cleanup of such objects is done for you when the context is 
released.
 .. function:: void gccjit::context::release ()
 
   This function releases all resources associated with the given context.
-  Both the context itself and all of its :c:type:`gccjit::object *`
+  Both the context itself and all of its :expr:`gccjit::object *`
   instances are cleaned up.  It should be called exactly once on a given
   context.
 
diff --git a/gcc/jit/docs/cp/topics/expressions.rst 
b/gcc/jit/docs/cp/topics/expressions.rst
index dec5b477811..01eb2898d0d 100644
--- a/gcc/jit/docs/cp/topics/expressions.rst
+++ b/gcc/jit/docs/cp/topics/expressions.rst
@@ -26,7 +26,7 @@ Rvalues
 
 A :class:`gccjit::rvalue` is an expression that can be computed.  It is a
 subclass of :class:`gccjit::object`, and is a thin wrapper around
-:c:type:`gcc_jit_rvalue *` from the C API.
+:c:expr:`gcc_jit_rvalue *` from the C API.
 
 It can be simple, e.g.:
 
@@ -491,7 +491,7 @@ a storage area (such as a variable).  It is a subclass of
 :class:`gccjit::rvalue`, where the rvalue is computed by reading from the
 storage area.
 
-It iss a thin wrapper around :c:type:`gcc_jit_lvalue *` from the C API.
+It iss a thin wrapper around :c:expr:`gcc_jit_lvalue *` from the C API.
 
 .. function:: gccjit::rvalue \
   gccjit::lvalue::get_address (gccjit::location loc)
diff --git a/gcc/jit/docs/cp/topics/functions.rst 

[PATCH 0/7] jit,docs: remove warnings and modernize the docs

2022-07-25 Thread Martin Liska
The patch set modernizes the documentation and removes most of the reported 
Sphinx
warnings.

Ready for master?
Thanks,
Martin

Martin Liska (7):
  jit,docs: use enum directive for enumeral types
  jit,docs: replace c:type:`int_type` with :expr:`int_type`
  jit,docs: various fixes
  jit,docs: compact function declarations
  jit,docs: use list-table instead of fixed table
  jit,docs: use :expr:`type *` for pointers to a type
  jit,docs: remove :ref:`modindex`

 gcc/jit/docs/conf.py  |   3 +
 gcc/jit/docs/cp/intro/tutorial02.rst  |   6 +-
 gcc/jit/docs/cp/intro/tutorial04.rst  |  73 +-
 gcc/jit/docs/cp/topics/asm.rst|   2 +-
 gcc/jit/docs/cp/topics/contexts.rst   |   8 +-
 gcc/jit/docs/cp/topics/expressions.rst|  52 --
 gcc/jit/docs/cp/topics/functions.rst  |  48 +-
 gcc/jit/docs/cp/topics/objects.rst|   2 +-
 gcc/jit/docs/cp/topics/types.rst  |   2 +-
 gcc/jit/docs/examples/tut04-toyvm/toyvm.c |   1 +
 gcc/jit/docs/index.rst|   8 --
 gcc/jit/docs/intro/tutorial02.rst |  16 ++--
 gcc/jit/docs/intro/tutorial03.rst |  28 +++---
 gcc/jit/docs/intro/tutorial04.rst |  77 ++-
 gcc/jit/docs/intro/tutorial05.rst |  41 +---
 gcc/jit/docs/topics/compilation.rst   |  38 
 gcc/jit/docs/topics/contexts.rst  |  12 +--
 gcc/jit/docs/topics/expressions.rst   | 111 ++
 gcc/jit/docs/topics/function-pointers.rst |   2 +-
 gcc/jit/docs/topics/functions.rst |   2 +-
 gcc/jit/docs/topics/objects.rst   |   6 +-
 gcc/jit/docs/topics/types.rst | 111 ++
 22 files changed, 379 insertions(+), 270 deletions(-)

-- 
2.37.1



[PATCH] rs6000: Adjust error messages.

2022-03-23 Thread Martin Liska
gcc/ChangeLog:

* config/rs6000/rs6000-c.cc (altivec_resolve_overloaded_builtin):
Use %qs in format.
* config/rs6000/rs6000.cc (rs6000_option_override_internal):
Reword the error message.
---
 gcc/config/rs6000/rs6000-c.cc | 5 +++--
 gcc/config/rs6000/rs6000.cc   | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc
index ad976753a3c..2f0f4fe337d 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -1788,8 +1788,9 @@ altivec_resolve_overloaded_builtin (location_t loc, tree 
fndecl,
{
  if (TYPE_READONLY (TREE_TYPE (type))
  && !TYPE_READONLY (TREE_TYPE (decl_type)))
-   warning (0, "passing argument %d of %qE discards % "
-"qualifier from pointer target type", n + 1, fndecl);
+   warning (0, "passing argument %d of %qE discards %qs "
+"qualifier from pointer target type", n + 1, fndecl,
+"const");
  type = build_qualified_type (TREE_TYPE (type), 0);
  type = build_pointer_type (type);
  arg = fold_convert (type, arg);
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index a7645820b1e..53c70b82529 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -4345,8 +4345,8 @@ rs6000_option_override_internal (bool global_init_p)
rs6000_veclib_handler = rs6000_builtin_vectorized_libmass;
  else
{
- error ("unknown vectorization library ABI type %qs for "
-"%qs switch", rs6000_veclibabi_name, "-mveclibabi=");
+ error ("unknown vectorization library type in "
+"%<-mveclibabi=%s%>", rs6000_veclibabi_name);
  ret = false;
}
}
-- 
2.35.1



[PATCH][V4] rs6000: Remove unnecessary option manipulation.

2021-11-12 Thread Martin Liska
Do not set flag_rename_registers, it's already enabled with 
EnabledBy(funroll-loops)
in the common.opt file. Use EnabledBy for unroll_only_small_loops which
is a canonical approach how can be make option dependencies.

gcc/ChangeLog:

* config/rs6000/rs6000.c (rs6000_override_options_after_change):
Do not set flag_rename_registers and unroll_only_small_loops.
* config/rs6000/rs6000.opt: Use EnabledBy for unroll_only_small_loops.
---
 gcc/config/rs6000/rs6000.c   | 7 +--
 gcc/config/rs6000/rs6000.opt | 2 +-
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index e4843eb0f1c..5550113a94c 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -3466,13 +3466,8 @@ rs6000_override_options_after_change (void)
   /* Explicit -funroll-loops turns -munroll-only-small-loops off, and
  turns -frename-registers on.  */
   if ((OPTION_SET_P (flag_unroll_loops) && flag_unroll_loops)
-   || (OPTION_SET_P (flag_unroll_all_loops)
-  && flag_unroll_all_loops))
+   || (OPTION_SET_P (flag_unroll_all_loops) && flag_unroll_all_loops))
 {
-  if (!OPTION_SET_P (unroll_only_small_loops))
-   unroll_only_small_loops = 0;
-  if (!OPTION_SET_P (flag_rename_registers))
-   flag_rename_registers = 1;
   if (!OPTION_SET_P (flag_cunroll_grow_size))
flag_cunroll_grow_size = 1;
 }
diff --git a/gcc/config/rs6000/rs6000.opt b/gcc/config/rs6000/rs6000.opt
index 9d7878f144a..faeb7423ca7 100644
--- a/gcc/config/rs6000/rs6000.opt
+++ b/gcc/config/rs6000/rs6000.opt
@@ -546,7 +546,7 @@ Target Undocumented Var(rs6000_optimize_swaps) Init(1) Save
 Analyze and remove doubleword swaps from VSX computations.
 
 munroll-only-small-loops
-Target Undocumented Var(unroll_only_small_loops) Init(0) Save
+Target Undocumented Var(unroll_only_small_loops) Init(0) Save 
EnabledBy(funroll-loops)
 ; Use conservative small loop unrolling.
 
 mpower9-misc
-- 
2.33.1



[PATCH][V3] rs6000: Remove unnecessary option manipulation.

2021-11-12 Thread Martin Liska
gcc/ChangeLog:

* config/rs6000/rs6000.c (rs6000_override_options_after_change):
Do not set flag_rename_registers, it's already enabled with 
EnabledBy(funroll-loops).
Use EnabledBy for unroll_only_small_loops.
* config/rs6000/rs6000.opt: Use EnabledBy for unroll_only_small_loops.
---
 gcc/config/rs6000/rs6000.c   | 7 +--
 gcc/config/rs6000/rs6000.opt | 2 +-
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index e4843eb0f1c..5550113a94c 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -3466,13 +3466,8 @@ rs6000_override_options_after_change (void)
   /* Explicit -funroll-loops turns -munroll-only-small-loops off, and
  turns -frename-registers on.  */
   if ((OPTION_SET_P (flag_unroll_loops) && flag_unroll_loops)
-   || (OPTION_SET_P (flag_unroll_all_loops)
-  && flag_unroll_all_loops))
+   || (OPTION_SET_P (flag_unroll_all_loops) && flag_unroll_all_loops))
 {
-  if (!OPTION_SET_P (unroll_only_small_loops))
-   unroll_only_small_loops = 0;
-  if (!OPTION_SET_P (flag_rename_registers))
-   flag_rename_registers = 1;
   if (!OPTION_SET_P (flag_cunroll_grow_size))
flag_cunroll_grow_size = 1;
 }
diff --git a/gcc/config/rs6000/rs6000.opt b/gcc/config/rs6000/rs6000.opt
index 9d7878f144a..faeb7423ca7 100644
--- a/gcc/config/rs6000/rs6000.opt
+++ b/gcc/config/rs6000/rs6000.opt
@@ -546,7 +546,7 @@ Target Undocumented Var(rs6000_optimize_swaps) Init(1) Save
 Analyze and remove doubleword swaps from VSX computations.
 
 munroll-only-small-loops
-Target Undocumented Var(unroll_only_small_loops) Init(0) Save
+Target Undocumented Var(unroll_only_small_loops) Init(0) Save 
EnabledBy(funroll-loops)
 ; Use conservative small loop unrolling.
 
 mpower9-misc
-- 
2.33.1



[PATCH] rs6000: Fix restored rs6000_long_double_type_size

2021-07-22 Thread Martin Liska
As mentioned in the "Fallout: save/restore target options in 
handle_optimize_attribute"
thread, we need to support target option restore
of rs6000_long_double_type_size == FLOAT_PRECISION_TFmode.

gcc/ChangeLog:

* config/rs6000/rs6000.c (rs6000_option_override_internal): When
a target option is restored, it can have
rs6000_long_double_type_size set to FLOAT_PRECISION_TFmode
and error should not be emitted.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pragma-optimize.c: New test.
---
 gcc/config/rs6000/rs6000.c |  2 ++
 gcc/testsuite/gcc.target/powerpc/pragma-optimize.c | 13 +
 2 files changed, 15 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pragma-optimize.c

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 279f00cc648..510936a9948 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -4186,6 +4186,8 @@ rs6000_option_override_internal (bool global_init_p)
   else
rs6000_long_double_type_size = default_long_double_size;
 }
+  else if (rs6000_long_double_type_size == FLOAT_PRECISION_TFmode)
+; /* The option value can be seen when cl_target_option_restore is called. 
 */
   else if (rs6000_long_double_type_size == 128)
 rs6000_long_double_type_size = FLOAT_PRECISION_TFmode;
   else if (global_options_set.x_rs6000_ieeequad)
diff --git a/gcc/testsuite/gcc.target/powerpc/pragma-optimize.c 
b/gcc/testsuite/gcc.target/powerpc/pragma-optimize.c
new file mode 100644
index 000..4a86b58f27c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pragma-optimize.c
@@ -0,0 +1,13 @@
+/* { dg-options "-O2 -mlong-double-128 -mabi=ibmlongdouble" } */
+
+extern unsigned long int x;
+extern float f (float);
+extern __typeof (f) f_power8;
+extern __typeof (f) f_power9;
+extern __typeof (f) f __attribute__ ((ifunc ("f_ifunc")));
+static __attribute__ ((optimize ("-fno-stack-protector"))) __typeof (f) *
+f_ifunc (void)
+{
+  __typeof (f) *res = x ? f_power9 : f_power8;
+  return res;
+}
-- 
2.32.0



[PATCH 3/4] Overhaul in isa_flags and handling it.

2021-04-21 Thread Martin Liska

gcc/ChangeLog:

* config/i386/i386-options.c (TARGET_EXPLICIT_NO_SAHF_P):
Define.
(SET_TARGET_NO_SAHF): Likewise.
(TARGET_EXPLICIT_PREFETCH_SSE_P): Likewise.
(SET_TARGET_PREFETCH_SSE): Likewise.
(TARGET_EXPLICIT_NO_TUNE_P): Likewise.
(SET_TARGET_NO_TUNE): Likewise.
(TARGET_EXPLICIT_NO_80387_P): Likewise.
(SET_TARGET_NO_80387): Likewise.
(DEF_PTA): New.
* config/i386/i386.h (TARGET_*): Remove.
* opth-gen.awk: Generate new used macros.
---
 gcc/config/i386/i386-options.c | 303 -
 gcc/config/i386/i386.h | 192 +
 gcc/opth-gen.awk   |  11 +-
 3 files changed, 45 insertions(+), 461 deletions(-)

diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
index 154234a6a44..2aef59d962c 100644
--- a/gcc/config/i386/i386-options.c
+++ b/gcc/config/i386/i386-options.c
@@ -2094,285 +2094,40 @@ ix86_option_override_internal (bool main_args_p,
 	else
 	  ix86_tune = PROCESSOR_GENERIC;
 
-	if (((processor_alias_table[i].flags & PTA_MMX) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_MMX))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_MMX;
-	if (((processor_alias_table[i].flags & PTA_3DNOW) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_3DNOW;
-	if (((processor_alias_table[i].flags & PTA_3DNOW_A) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW_A))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_A;
-	if (((processor_alias_table[i].flags & PTA_SSE) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE;
-	if (((processor_alias_table[i].flags & PTA_SSE2) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE2))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE2;
-	if (((processor_alias_table[i].flags & PTA_SSE3) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE3))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
-	if (((processor_alias_table[i].flags & PTA_SSSE3) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSSE3))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSSE3;
-	if (((processor_alias_table[i].flags & PTA_SSE4_1) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_1))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1;
-	if (((processor_alias_table[i].flags & PTA_SSE4_2) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_2))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2;
-	if (((processor_alias_table[i].flags & PTA_AVX) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX;
-	if (((processor_alias_table[i].flags & PTA_AVX2) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX2))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX2;
-	if (((processor_alias_table[i].flags & PTA_FMA) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FMA;
-	if (((processor_alias_table[i].flags & PTA_SSE4A) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4A))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE4A;
-	if (((processor_alias_table[i].flags & PTA_FMA4) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA4))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FMA4;
-	if (((processor_alias_table[i].flags & PTA_XOP) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XOP))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XOP;
-	if (((processor_alias_table[i].flags & PTA_LWP) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_LWP))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_LWP;
+	/* Enable PTA flags that are enabled by default by a -march option.  */
+#define TARGET_EXPLICIT_NO_SAHF_P(opts) (false)
+#define SET_TARGET_NO_SAHF(opts) {}
+#define TARGET_EXPLICIT_PREFETCH_SSE_P(opts) (false)
+#define SET_TARGET_PREFETCH_SSE(opts) {}
+#define TARGET_EXPLICIT_NO_TUNE_P(opts) (false)
+#define SET_TARGET_NO_TUNE(opts) {}
+#define TARGET_EXPLICIT_NO_80387_P(opts) (false)
+#define SET_TARGET_NO_80387(opts) {}
+
+#define DEF_PTA(NAME) \
+	if (((processor_alias_table[i].flags & PTA_ ## NAME) != 0) \
+	&& PTA_ ## NAME != PTA_64BIT \
+	&& !TARGET_EXPLICIT_ ## NAME ## _P (opts)) \
+	  SET_TARGET_ ## NAME (opts);
+#include "i386.def"
+#undef DEF_PTA
+
+
+   if (!(TARGET_64BIT_P (opts->x_ix86_isa_flags)
+   && ((processor_alias_table[i].flags & PTA_NO_SAHF) != 0))
+	   && !TARGET_EXPLICIT_SAHF_P (opts))
+	SET_TARGET_SAHF (opts);
+
 	if (((processor_alias_table[i].flags & PTA_ABM) != 0)
-	&& !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_ABM))
-	  opts->x_ix86_isa_flags |= OPTION_MASK_ISA_ABM;
-	if 

[PATCH 4/4] Remove TARGET_foo (ix86_tune == PROCESSOR_foo) macros.

2021-04-21 Thread Martin Liska

gcc/ChangeLog:

* config/i386/i386-expand.c (decide_alignment): Use newly named
macro TARGET_CPU_P.
* config/i386/i386.c (ix86_decompose_address): Likewise.
(ix86_address_cost): Likewise.
(ix86_lea_outperforms): Likewise.
(ix86_avoid_lea_for_addr): Likewise.
(ix86_add_stmt_cost): Likewise.
* config/i386/i386.h (TARGET_*): Remove.
(TARGET_CPU_P): New macro.
* config/i386/i386.md: Use newly named macro TARGET_CPU_P.
* config/i386/x86-tune-sched-atom.c (do_reorder_for_imul): Likewise.
(swap_top_of_ready_list): Likewise.
(ix86_atom_sched_reorder): Likewise.
* config/i386/x86-tune-sched-bd.c (ix86_bd_has_dispatch): Likewise.
* config/i386/x86-tune-sched.c (ix86_adjust_cost): Likewise.
---
 gcc/config/i386/i386-expand.c |  2 +-
 gcc/config/i386/i386.c| 16 ++
 gcc/config/i386/i386.h| 46 +--
 gcc/config/i386/i386.md   |  8 ++---
 gcc/config/i386/x86-tune-sched-atom.c |  7 ++--
 gcc/config/i386/x86-tune-sched-bd.c   |  5 +--
 gcc/config/i386/x86-tune-sched.c  |  2 +-
 7 files changed, 23 insertions(+), 63 deletions(-)

diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index dda08ff67f2..166c23ddb4d 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -7055,7 +7055,7 @@ decide_alignment (int align,
   desired_align = GET_MODE_SIZE (move_mode);
   /* PentiumPro has special logic triggering for 8 byte aligned blocks.
  copying whole cacheline at once.  */
-  if (TARGET_PENTIUMPRO
+  if (TARGET_CPU_P (PENTIUMPRO)
   && (alg == rep_prefix_4_byte || alg == rep_prefix_1_byte))
 desired_align = 8;
 
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 7c41302c75b..c302bc2359a 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -10179,7 +10179,7 @@ ix86_decompose_address (rtx addr, struct ix86_address *out)
  Avoid this by transforming to [%esi+0].
  Reload calls address legitimization without cfun defined, so we need
  to test cfun for being non-NULL. */
-  if (TARGET_K6 && cfun && optimize_function_for_speed_p (cfun)
+  if (TARGET_CPU_P (K6) && cfun && optimize_function_for_speed_p (cfun)
   && base_reg && !index_reg && !disp
   && REGNO (base_reg) == SI_REG)
 disp = const0_rtx;
@@ -10257,7 +10257,7 @@ ix86_address_cost (rtx x, machine_mode, addr_space_t, bool)
  memory address, but I don't have AMD-K6 machine handy to check this
  theory.  */
 
-  if (TARGET_K6
+  if (TARGET_CPU_P (K6)
   && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
 	  || (parts.disp && !parts.base && parts.index && parts.scale != 1)
 	  || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
@@ -14940,7 +14940,7 @@ ix86_lea_outperforms (rtx_insn *insn, unsigned int regno0, unsigned int regno1,
   /* For Atom processors newer than Bonnell, if using a 2-source or
  3-source LEA for non-destructive destination purposes, or due to
  wanting ability to use SCALE, the use of LEA is justified.  */
-  if (!TARGET_BONNELL)
+  if (!TARGET_CPU_P (BONNELL))
 {
   if (has_scale)
 	return true;
@@ -15082,7 +15082,7 @@ ix86_avoid_lea_for_addr (rtx_insn *insn, rtx operands[])
  than lea for most processors.  For the processors like BONNELL, if
  the destination register of LEA holds an actual address which will
  be used soon, LEA is better and otherwise ADD is better.  */
-  if (!TARGET_BONNELL
+  if (!TARGET_CPU_P (BONNELL)
   && parts.scale == 1
   && (!parts.disp || parts.disp == const0_rtx)
   && (regno0 == regno1 || regno0 == regno2))
@@ -22387,7 +22387,7 @@ ix86_add_stmt_cost (class vec_info *vinfo, void *data, int count,
 stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
 
   /* Penalize DFmode vector operations for Bonnell.  */
-  if (TARGET_BONNELL && kind == vector_stmt
+  if (TARGET_CPU_P (BONNELL) && kind == vector_stmt
   && vectype && GET_MODE_INNER (TYPE_MODE (vectype)) == DFmode)
 stmt_cost *= 5;  /* FIXME: The value here is arbitrary.  */
 
@@ -22403,8 +22403,10 @@ ix86_add_stmt_cost (class vec_info *vinfo, void *data, int count,
   /* We need to multiply all vector stmt cost by 1.7 (estimated cost)
  for Silvermont as it has out of order integer pipeline and can execute
  2 scalar instruction per tick, but has in order SIMD pipeline.  */
-  if ((TARGET_SILVERMONT || TARGET_GOLDMONT || TARGET_GOLDMONT_PLUS
-   || TARGET_TREMONT || TARGET_INTEL) && stmt_info && stmt_info->stmt)
+  if ((TARGET_CPU_P (SILVERMONT) || TARGET_CPU_P (GOLDMONT)
+   || TARGET_CPU_P (GOLDMONT_PLUS) || TARGET_CPU_P (TREMONT)
+   || TARGET_CPU_P (INTEL))
+  && stmt_info && stmt_info->stmt)
 {
   tree lhs_op = gimple_get_lhs (stmt_info->stmt);
   if (lhs_op && TREE_CODE (TREE_TYPE (lhs_op)) == 

[PATCH 2/4] Generate PTA features from a def file.

2021-04-21 Thread Martin Liska

gcc/ChangeLog:

* config/i386/i386.h (PTA_*): Remove.
(enum pta_flag): New.
(DEF_PTA): Generate PTA_* values from i386.def.
* wide-int-bitmask.h (WIDE_INT_BITMASK_FROM_NTH): New macro.
* config/i386/i386.def: New file.
---
 gcc/config/i386/i386.def | 110 +++
 gcc/config/i386/i386.h   | 106 ++---
 gcc/wide-int-bitmask.h   |   3 ++
 3 files changed, 128 insertions(+), 91 deletions(-)
 create mode 100644 gcc/config/i386/i386.def

diff --git a/gcc/config/i386/i386.def b/gcc/config/i386/i386.def
new file mode 100644
index 000..a0d46cbc892
--- /dev/null
+++ b/gcc/config/i386/i386.def
@@ -0,0 +1,110 @@
+/* Definition for processor table alias flags.
+   Copyright (C) 2001-2021 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+DEF_PTA(3DNOW)
+DEF_PTA(3DNOW_A)
+DEF_PTA(64BIT)
+DEF_PTA(ABM)
+DEF_PTA(AES)
+DEF_PTA(AVX)
+DEF_PTA(BMI)
+DEF_PTA(CX16)
+DEF_PTA(F16C)
+DEF_PTA(FMA)
+DEF_PTA(FMA4)
+DEF_PTA(FSGSBASE)
+DEF_PTA(LWP)
+DEF_PTA(LZCNT)
+DEF_PTA(MMX)
+DEF_PTA(MOVBE)
+DEF_PTA(NO_SAHF)
+DEF_PTA(PCLMUL)
+DEF_PTA(POPCNT)
+DEF_PTA(PREFETCH_SSE)
+DEF_PTA(RDRND)
+DEF_PTA(SSE)
+DEF_PTA(SSE2)
+DEF_PTA(SSE3)
+DEF_PTA(SSE4_1)
+DEF_PTA(SSE4_2)
+DEF_PTA(SSE4A)
+DEF_PTA(SSSE3)
+DEF_PTA(TBM)
+DEF_PTA(XOP)
+DEF_PTA(AVX2)
+DEF_PTA(BMI2)
+DEF_PTA(RTM)
+DEF_PTA(HLE)
+DEF_PTA(PRFCHW)
+DEF_PTA(RDSEED)
+DEF_PTA(ADX)
+DEF_PTA(FXSR)
+DEF_PTA(XSAVE)
+DEF_PTA(XSAVEOPT)
+DEF_PTA(AVX512F)
+DEF_PTA(AVX512ER)
+DEF_PTA(AVX512PF)
+DEF_PTA(AVX512CD)
+DEF_PTA(NO_TUNE)
+DEF_PTA(SHA)
+DEF_PTA(PREFETCHWT1)
+DEF_PTA(CLFLUSHOPT)
+DEF_PTA(XSAVEC)
+DEF_PTA(XSAVES)
+DEF_PTA(AVX512DQ)
+DEF_PTA(AVX512BW)
+DEF_PTA(AVX512VL)
+DEF_PTA(AVX512IFMA)
+DEF_PTA(AVX512VBMI)
+DEF_PTA(CLWB)
+DEF_PTA(MWAITX)
+DEF_PTA(CLZERO)
+DEF_PTA(NO_80387)
+DEF_PTA(PKU)
+DEF_PTA(AVX5124VNNIW)
+DEF_PTA(AVX5124FMAPS)
+DEF_PTA(AVX512VPOPCNTDQ)
+DEF_PTA(SGX)
+DEF_PTA(AVX512VNNI)
+DEF_PTA(GFNI)
+DEF_PTA(VAES)
+DEF_PTA(AVX512VBMI2)
+DEF_PTA(VPCLMULQDQ)
+DEF_PTA(AVX512BITALG)
+DEF_PTA(RDPID)
+DEF_PTA(PCONFIG)
+DEF_PTA(WBNOINVD)
+DEF_PTA(AVX512VP2INTERSECT)
+DEF_PTA(PTWRITE)
+DEF_PTA(AVX512BF16)
+DEF_PTA(WAITPKG)
+DEF_PTA(MOVDIRI)
+DEF_PTA(MOVDIR64B)
+DEF_PTA(ENQCMD)
+DEF_PTA(CLDEMOTE)
+DEF_PTA(SERIALIZE)
+DEF_PTA(TSXLDTRK)
+DEF_PTA(AMX_TILE)
+DEF_PTA(AMX_INT8)
+DEF_PTA(AMX_BF16)
+DEF_PTA(UINTR)
+DEF_PTA(HRESET)
+DEF_PTA(KL)
+DEF_PTA(WIDEKL)
+DEF_PTA(AVXVNNI)
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 97700d797a7..cee5190f0c7 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2413,97 +2413,21 @@ extern const char *const processor_names[];
 
 #include "wide-int-bitmask.h"
 
-constexpr wide_int_bitmask PTA_3DNOW (HOST_WIDE_INT_1U << 0);
-constexpr wide_int_bitmask PTA_3DNOW_A (HOST_WIDE_INT_1U << 1);
-constexpr wide_int_bitmask PTA_64BIT (HOST_WIDE_INT_1U << 2);
-constexpr wide_int_bitmask PTA_ABM (HOST_WIDE_INT_1U << 3);
-constexpr wide_int_bitmask PTA_AES (HOST_WIDE_INT_1U << 4);
-constexpr wide_int_bitmask PTA_AVX (HOST_WIDE_INT_1U << 5);
-constexpr wide_int_bitmask PTA_BMI (HOST_WIDE_INT_1U << 6);
-constexpr wide_int_bitmask PTA_CX16 (HOST_WIDE_INT_1U << 7);
-constexpr wide_int_bitmask PTA_F16C (HOST_WIDE_INT_1U << 8);
-constexpr wide_int_bitmask PTA_FMA (HOST_WIDE_INT_1U << 9);
-constexpr wide_int_bitmask PTA_FMA4 (HOST_WIDE_INT_1U << 10);
-constexpr wide_int_bitmask PTA_FSGSBASE (HOST_WIDE_INT_1U << 11);
-constexpr wide_int_bitmask PTA_LWP (HOST_WIDE_INT_1U << 12);
-constexpr wide_int_bitmask PTA_LZCNT (HOST_WIDE_INT_1U << 13);
-constexpr wide_int_bitmask PTA_MMX (HOST_WIDE_INT_1U << 14);
-constexpr wide_int_bitmask PTA_MOVBE (HOST_WIDE_INT_1U << 15);
-constexpr wide_int_bitmask PTA_NO_SAHF (HOST_WIDE_INT_1U << 16);
-constexpr wide_int_bitmask PTA_PCLMUL (HOST_WIDE_INT_1U << 17);
-constexpr wide_int_bitmask PTA_POPCNT (HOST_WIDE_INT_1U << 18);
-constexpr wide_int_bitmask PTA_PREFETCH_SSE (HOST_WIDE_INT_1U << 19);
-constexpr wide_int_bitmask PTA_RDRND (HOST_WIDE_INT_1U << 20);
-constexpr wide_int_bitmask PTA_SSE (HOST_WIDE_INT_1U << 21);
-constexpr wide_int_bitmask PTA_SSE2 (HOST_WIDE_INT_1U << 22);
-constexpr wide_int_bitmask PTA_SSE3 (HOST_WIDE_INT_1U << 23);
-constexpr wide_int_bitmask PTA_SSE4_1 (HOST_WIDE_INT_1U << 24);
-constexpr wide_int_bitmask PTA_SSE4_2 (HOST_WIDE_INT_1U << 25);
-constexpr wide_int_bitmask 

[PATCH 1/4] Remove DEF_ENUM from stringop.def.

2021-04-21 Thread Martin Liska

gcc/ChangeLog:

* config/i386/i386-options.c (DEF_ENUM): Remove it.
* config/i386/i386-opts.h (DEF_ENUM): Likewise.
* config/i386/stringop.def (DEF_ENUM): Likewise.
---
 gcc/config/i386/i386-options.c | 2 --
 gcc/config/i386/i386-opts.h| 4 
 gcc/config/i386/stringop.def   | 9 -
 3 files changed, 15 deletions(-)

diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
index 7e59ccd988d..154234a6a44 100644
--- a/gcc/config/i386/i386-options.c
+++ b/gcc/config/i386/i386-options.c
@@ -1455,10 +1455,8 @@ ix86_valid_target_attribute_p (tree fndecl,
 }
 
 const char *stringop_alg_names[] = {
-#define DEF_ENUM
 #define DEF_ALG(alg, name) #name,
 #include "stringop.def"
-#undef DEF_ENUM
 #undef DEF_ALG
 };
 
diff --git a/gcc/config/i386/i386-opts.h b/gcc/config/i386/i386-opts.h
index de6e7e01661..04e4ad608fb 100644
--- a/gcc/config/i386/i386-opts.h
+++ b/gcc/config/i386/i386-opts.h
@@ -28,16 +28,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 /* Algorithm to expand string function with.  */
 enum stringop_alg
 {
-#undef DEF_ENUM
-#define DEF_ENUM
-
 #undef DEF_ALG
 #define DEF_ALG(alg, name) alg, 
 
 #include "stringop.def"
 last_alg
 
-#undef DEF_ENUM
 #undef DEF_ALG
 };
 
diff --git a/gcc/config/i386/stringop.def b/gcc/config/i386/stringop.def
index 76898d26435..cd34b7e6b7d 100644
--- a/gcc/config/i386/stringop.def
+++ b/gcc/config/i386/stringop.def
@@ -17,21 +17,12 @@ You should have received a copy of the GNU General Public License
 along with GCC; see the files COPYING3.  If not,
 see .  */
 
-DEF_ENUM
 DEF_ALG (no_stringop, no_stringop)
-DEF_ENUM
 DEF_ALG (libcall, libcall)
-DEF_ENUM
 DEF_ALG (rep_prefix_1_byte, rep_byte)
-DEF_ENUM
 DEF_ALG (rep_prefix_4_byte, rep_4byte)
-DEF_ENUM
 DEF_ALG (rep_prefix_8_byte, rep_8byte)
-DEF_ENUM
 DEF_ALG (loop_1_byte, byte_loop)
-DEF_ENUM
 DEF_ALG (loop, loop)
-DEF_ENUM
 DEF_ALG (unrolled_loop, unrolled_loop)
-DEF_ENUM
 DEF_ALG (vector_loop, vector_loop)


[PATCH 0/4] i386: ISA flags and PTA simplification

2021-04-21 Thread Martin Liska
Hello.

I've spent some time reading the i386 back-end and I noticed various
boilerplate code can be simplified.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed once GCC 11.1 is released?
Thanks,
Martin

Martin Liska (4):
  Remove DEF_ENUM from stringop.def.
  Generate PTA features from a def file.
  Overhaul in isa_flags and handling it.
  Remove TARGET_foo (ix86_tune == PROCESSOR_foo) macros.

 gcc/config/i386/i386-expand.c |   2 +-
 gcc/config/i386/i386-options.c| 305 +++
 gcc/config/i386/i386-opts.h   |   4 -
 gcc/config/i386/i386.c|  16 +-
 gcc/config/i386/i386.def  | 110 
 gcc/config/i386/i386.h| 344 ++
 gcc/config/i386/i386.md   |   8 +-
 gcc/config/i386/stringop.def  |   9 -
 gcc/config/i386/x86-tune-sched-atom.c |   7 +-
 gcc/config/i386/x86-tune-sched-bd.c   |   5 +-
 gcc/config/i386/x86-tune-sched.c  |   2 +-
 gcc/opth-gen.awk  |  11 +-
 gcc/wide-int-bitmask.h|   3 +
 13 files changed, 196 insertions(+), 630 deletions(-)
 create mode 100644 gcc/config/i386/i386.def

-- 
2.31.1



[PATCH 0/4] Remove BRIG FE and libhsail

2021-04-21 Thread Martin Liska
Based on the discussion with Martin Jambor, I'm suggesting removal
of the HSA front-end and BRIG FE. Both were marked as obsolete in GCC 11.

Ready to be installed once GCC 11.1 is released?
Thanks,
Martin

Martin Liska (4):
  gcc-changelog: Remove components that will be removed.
  Remove BRIG front-end.
  Remove libhsail-rt.
  Remove dead components from MAINTAINERS.

 MAINTAINERS   | 5 -
 Makefile.def  | 3 -
 Makefile.in   |   489 -
 configure |24 -
 configure.ac  |21 -
 contrib/gcc-changelog/git_commit.py   | 2 -
 contrib/gcc_update| 4 -
 contrib/update-copyright.py   | 2 -
 gcc/ada/gcc-interface/ada-tree.h  | 6 +-
 gcc/brig-builtins.def |   675 -
 gcc/brig/ChangeLog|   433 -
 gcc/brig/Make-lang.in |   251 -
 gcc/brig/brig-builtins.h  |99 -
 gcc/brig/brig-c.h |66 -
 gcc/brig/brig-lang.c  |   958 -
 .../brigfrontend/brig-arg-block-handler.cc|66 -
 .../brigfrontend/brig-atomic-inst-handler.cc  |   265 -
 .../brigfrontend/brig-basic-inst-handler.cc   |   735 -
 .../brigfrontend/brig-branch-inst-handler.cc  |   238 -
 .../brigfrontend/brig-cmp-inst-handler.cc |   198 -
 .../brigfrontend/brig-code-entry-handler.cc   |  1305 --
 .../brigfrontend/brig-code-entry-handler.h|   410 -
 gcc/brig/brigfrontend/brig-comment-handler.cc |38 -
 gcc/brig/brigfrontend/brig-control-handler.cc |   108 -
 .../brig-copy-move-inst-handler.cc|73 -
 .../brigfrontend/brig-cvt-inst-handler.cc |   268 -
 .../brigfrontend/brig-fbarrier-handler.cc |45 -
 .../brigfrontend/brig-function-handler.cc |   431 -
 gcc/brig/brigfrontend/brig-function.cc|  1602 --
 gcc/brig/brigfrontend/brig-function.h |   267 -
 .../brigfrontend/brig-inst-mod-handler.cc |58 -
 gcc/brig/brigfrontend/brig-label-handler.cc   |40 -
 .../brigfrontend/brig-lane-inst-handler.cc|85 -
 gcc/brig/brigfrontend/brig-machine.c  |44 -
 gcc/brig/brigfrontend/brig-machine.h  |33 -
 .../brigfrontend/brig-mem-inst-handler.cc |   178 -
 gcc/brig/brigfrontend/brig-module-handler.cc  |41 -
 .../brigfrontend/brig-queue-inst-handler.cc   |93 -
 .../brigfrontend/brig-seg-inst-handler.cc |   146 -
 .../brigfrontend/brig-signal-inst-handler.cc  |42 -
 gcc/brig/brigfrontend/brig-to-generic.cc  |  1045 -
 gcc/brig/brigfrontend/brig-to-generic.h   |   240 -
 gcc/brig/brigfrontend/brig-util.cc|   574 -
 gcc/brig/brigfrontend/brig-util.h |   120 -
 .../brigfrontend/brig-variable-handler.cc |   270 -
 gcc/brig/brigfrontend/hsa-brig-format.h   |  1234 --
 gcc/brig/brigfrontend/phsa.h  |79 -
 gcc/brig/brigspec.c   |   136 -
 gcc/brig/config-lang.in   |41 -
 gcc/brig/gccbrig.texi |   153 -
 gcc/brig/lang-specs.h |28 -
 gcc/brig/lang.opt |46 -
 gcc/builtins.def  |43 -
 gcc/doc/frontends.texi| 2 +-
 gcc/doc/install.texi  | 6 +-
 gcc/doc/invoke.texi   | 4 -
 gcc/doc/standards.texi| 8 -
 gcc/testsuite/brig.dg/README  |12 -
 gcc/testsuite/brig.dg/dg.exp  |31 -
 .../brig.dg/test/gimple/alloca.hsail  |37 -
 .../brig.dg/test/gimple/atomics.hsail |33 -
 .../brig.dg/test/gimple/branches.hsail|58 -
 .../brig.dg/test/gimple/fbarrier.hsail|74 -
 .../brig.dg/test/gimple/function_calls.hsail  |59 -
 .../brig.dg/test/gimple/internal-casts.hsail  |   146 -
 .../brig.dg/test/gimple/kernarg.hsail |25 -
 gcc/testsuite/brig.dg/test/gimple/mem.hsail   |39 -
 gcc/testsuite/brig.dg/test/gimple/mulhi.hsail |33 -
 .../brig.dg/test/gimple/packed.hsail  |76 -
 .../gimple/priv-array-offset-access.hsail |87 -
 .../brig.dg/test/gimple/smoke_test.hsail  |91 -
 .../brig.dg/test/gimple/variables.hsail   |   125 -
 .../brig.dg/test/gimple/vector.hsail  |57 -
 gcc/testsuite/gfortran.dg/goacc/pr78027.f90   | 4 -
 gcc/testsuite/lib/brig-dg.exp |29 -
 gcc/testsuite/lib/brig.exp|40 -
 libhsail-rt/ChangeLog |   164 -
 libhsail-rt/Makefile.am   |   122 -
 libhsail-rt/Makefile.in   |   817 -
 libhsail-rt/README|10 -
 libhsail-rt/aclocal.m4|  1179

[PATCH 4/4] Remove dead components from MAINTAINERS.

2021-04-21 Thread Martin Liska

ChangeLog:

* MAINTAINERS: Remove entries for removed
components (HSA, BRIG, libhsail-rt).
---
 MAINTAINERS | 5 -
 1 file changed, 5 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index db25583b37b..d3101d5c47f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -150,8 +150,6 @@ C front end/ISO C99	Joseph Myers		
 Ada front end		Arnaud Charlet		
 Ada front end		Eric Botcazou		
 Ada front end		Pierre-Marie de Rodat	
-BRIG (HSAIL) front end	Pekka Jääskeläinen	
-BRIG (HSAIL) front end 	Martin Jambor		
 c++			Jason Merrill		
 c++			Nathan Sidwell		
 D front end		Iain Buclaw		
@@ -177,8 +175,6 @@ libobjc			Andrew Pinski		
 libquadmath		Tobias Burnus		
 libquadmath		Jakub Jelinek		
 libvtv			Caroline Tice		
-libhsail-rt		Pekka Jääskeläinen	
-libhsail-rt		Martin Jambor		
 libphobos		Iain Buclaw		
 line map		Dodji Seketeli		
 soft-fp			Joseph Myers		
@@ -204,7 +200,6 @@ fixincludes		Bruce Korb		
 *gimpl*			Jason Merrill		
 gcse.c			Jeff Law		
 global opt framework	Jeff Law		
-hsa			Martin Jambor		
 jump.c			David S. Miller		
 web pages		Gerald Pfeifer		
 config.sub/config.guess	Ben Elliston		


[PATCH 1/4] gcc-changelog: Remove components that will be removed.

2021-04-21 Thread Martin Liska

contrib/ChangeLog:

* gcc-changelog/git_commit.py: Remove components that will be
removed.
---
 contrib/gcc-changelog/git_commit.py | 2 --
 1 file changed, 2 deletions(-)

diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py
index b28f7deac23..89461cc027d 100755
--- a/contrib/gcc-changelog/git_commit.py
+++ b/contrib/gcc-changelog/git_commit.py
@@ -30,7 +30,6 @@ changelog_locations = {
 'fixincludes',
 'gcc/ada',
 'gcc/analyzer',
-'gcc/brig',
 'gcc/c',
 'gcc/c-family',
 'gcc',
@@ -62,7 +61,6 @@ changelog_locations = {
 'libgcc/config/libbid',
 'libgfortran',
 'libgomp',
-'libhsail-rt',
 'libiberty',
 'libitm',
 'libobjc',


[PATCH 1/3] Come up with startswith function.

2021-04-21 Thread Martin Liska

gcc/ada/ChangeLog:

* adadecode.c (has_prefix): Remove has_prefix and replace it
with startswith.
(__gnat_decode): Likewise.
* gcc-interface/utils.c (def_builtin_1): Use startswith
function instead of strncmp.
* init.c (__gnat_install_handler): Likewise.

gcc/analyzer/ChangeLog:

* sm-file.cc (is_file_using_fn_p): Use startswith
function instead of strncmp.

gcc/ChangeLog:

* builtins.c (is_builtin_name): Use startswith
function instead of strncmp.
* collect2.c (main): Likewise.
(has_lto_section): Likewise.
(scan_libraries): Likewise.
* coverage.c (coverage_checksum_string): Likewise.
(coverage_init): Likewise.
* dwarf2out.c (is_cxx): Likewise.
(gen_compile_unit_die): Likewise.
* gcc-ar.c (main): Likewise.
* gcc.c (init_spec): Likewise.
(read_specs): Likewise.
(execute): Likewise.
(check_live_switch): Likewise.
* genattrtab.c (write_attr_case): Likewise.
(IS_ATTR_GROUP): Likewise.
* gencfn-macros.c (main): Likewise.
* gengtype.c (type_for_name): Likewise.
(gen_rtx_next): Likewise.
(get_file_langdir): Likewise.
(write_local): Likewise.
* genmatch.c (get_operator): Likewise.
(get_operand_type): Likewise.
(expr::gen_transform): Likewise.
* genoutput.c (validate_optab_operands): Likewise.
* incpath.c (add_sysroot_to_chain): Likewise.
* langhooks.c (lang_GNU_C): Likewise.
(lang_GNU_CXX): Likewise.
(lang_GNU_Fortran): Likewise.
(lang_GNU_OBJC): Likewise.
* lto-wrapper.c (run_gcc): Likewise.
* omp-general.c (omp_max_simt_vf): Likewise.
* omp-low.c (omp_runtime_api_call): Likewise.
* opts-common.c (parse_options_from_collect_gcc_options): Likewise.
* read-rtl-function.c (function_reader::read_rtx_operand_r): Likewise.
* real.c (real_from_string): Likewise.
* selftest.c (assert_str_startswith): Likewise.
* timevar.c (timer::validate_phases): Likewise.
* tree.c (get_file_function_name): Likewise.
* ubsan.c (ubsan_use_new_style_p): Likewise.
* varasm.c (default_function_rodata_section): Likewise.
(incorporeal_function_p): Likewise.
(default_section_type_flags): Likewise.
* system.h (startswith): Define startswith.

gcc/c-family/ChangeLog:

* c-ada-spec.c (print_destructor): Use startswith
function instead of strncmp.
(dump_ada_declaration): Likewise.
* c-common.c (disable_builtin_function): Likewise.
(def_builtin_1): Likewise.
* c-format.c (check_tokens): Likewise.
(check_plain): Likewise.
(convert_format_name_to_system_name): Likewise.

gcc/c/ChangeLog:

* c-aux-info.c (affix_data_type): Use startswith
function instead of strncmp.
* c-typeck.c (build_function_call_vec): Likewise.
* gimple-parser.c (c_parser_gimple_parse_bb_spec): Likewise.

gcc/cp/ChangeLog:

* decl.c (duplicate_decls): Use startswith
function instead of strncmp.
(cxx_builtin_function): Likewise.
(omp_declare_variant_finalize_one): Likewise.
(grokfndecl): Likewise.
* error.c (dump_decl_name): Likewise.
* mangle.c (find_decomp_unqualified_name): Likewise.
(write_guarded_var_name): Likewise.
(decl_tls_wrapper_p): Likewise.
* parser.c (cp_parser_simple_type_specifier): Likewise.
(cp_parser_tx_qualifier_opt): Likewise.
* pt.c (template_parm_object_p): Likewise.
(dguide_name_p): Likewise.

gcc/d/ChangeLog:

* d-builtins.cc (do_build_builtin_fn): Use startswith
function instead of strncmp.
* dmd/dinterpret.c (evaluateIfBuiltin): Likewise.
* dmd/dmangle.c: Likewise.
* dmd/hdrgen.c: Likewise.
* dmd/identifier.c (Identifier::toHChars2): Likewise.

gcc/fortran/ChangeLog:

* decl.c (variable_decl): Use startswith
function instead of strncmp.
(gfc_match_end): Likewise.
* gfortran.h (gfc_str_startswith): Likewise.
* module.c (load_omp_udrs): Likewise.
(read_module): Likewise.
* options.c (gfc_handle_runtime_check_option): Likewise.
* primary.c (match_arg_list_function): Likewise.
* trans-decl.c (gfc_get_symbol_decl): Likewise.
* trans-expr.c (gfc_conv_procedure_call): Likewise.
* trans-intrinsic.c (gfc_conv_ieee_arithmetic_function): Likewise.

gcc/go/ChangeLog:

* gofrontend/runtime.cc (Runtime::name_to_code): Use startswith
function instead of strncmp.

gcc/objc/ChangeLog:

* objc-act.c (objc_string_ref_type_p): Use startswith
function instead of strncmp.
* objc-encoding.c (encode_type): Likewise.
* objc-next-runtime-abi-02.c (has_load_impl): Likewise.
---
 

[PATCH 3/3] Use startswith in targets.

2021-04-21 Thread Martin Liska

gcc/ChangeLog:

* common/config/aarch64/aarch64-common.c (aarch64_parse_extension):
Use startswith function instead of strncmp.
* common/config/bfin/bfin-common.c (bfin_handle_option): Likewise.
* common/config/riscv/riscv-common.c (riscv_subset_list::parse): 
Likewise.
* config/aarch64/aarch64-sve-builtins-shapes.cc (parse_type): Likewise.
* config/aarch64/aarch64.c (aarch64_process_one_target_attr): Likewise.
* config/alpha/alpha.c (alpha_elf_section_type_flags): Likewise.
* config/arm/aarch-common.c (arm_md_asm_adjust): Likewise.
* config/arm/arm.c (arm_file_start): Likewise.
(arm_valid_target_attribute_rec): Likewise.
(thumb1_md_asm_adjust): Likewise.
* config/arm/driver-arm.c (host_detect_local_cpu): Likewise.
* config/avr/avr.c (STR_PREFIX_P): Likewise.
(avr_set_current_function): Likewise.
(avr_handle_addr_attribute): Likewise.
(avr_asm_output_aligned_decl_common): Likewise.
(avr_asm_named_section): Likewise.
(avr_section_type_flags): Likewise.
(avr_asm_select_section): Likewise.
* config/c6x/c6x.c (c6x_in_small_data_p): Likewise.
(c6x_section_type_flags): Likewise.
* config/darwin-c.c (darwin_cfstring_ref_p): Likewise.
(darwin_objc_declare_unresolved_class_reference): Likewise.
(darwin_objc_declare_class_definition): Likewise.
* config/darwin.c (indirect_data): Likewise.
(darwin_encode_section_info): Likewise.
(darwin_objc2_section): Likewise.
(darwin_objc1_section): Likewise.
(machopic_select_section): Likewise.
(darwin_globalize_label): Likewise.
(darwin_label_is_anonymous_local_objc_name): Likewise.
(darwin_asm_named_section): Likewise.
(darwin_asm_output_dwarf_offset): Likewise.
* config/frv/frv.c (frv_string_begins_with): Likewise.
(frv_in_small_data_p): Likewise.
* config/gcn/mkoffload.c (STR): Likewise.
(main): Likewise.
* config/i386/i386-builtins.c (get_builtin_code_for_version): Likewise.
* config/i386/i386-options.c (ix86_option_override_internal): Likewise.
* config/i386/i386.c (x86_64_elf_section_type_flags): Likewise.
(ix86_md_asm_adjust): Likewise.
* config/i386/intelmic-mkoffload.c (STR): Likewise.
* config/i386/winnt.c (i386_pe_asm_named_section): Likewise.
(i386_pe_file_end): Likewise.
* config/ia64/ia64.c (ia64_in_small_data_p): Likewise.
(ia64_section_type_flags): Likewise.
* config/mips/driver-native.c (host_detect_local_cpu): Likewise.
* config/mips/mips.c (mips_handle_interrupt_attr): Likewise.
(mips16_stub_function_p): Likewise.
(mips_function_rodata_section): Likewise.
* config/msp430/msp430.c (msp430_mcu_name): Likewise.
(msp430_function_section): Likewise.
(msp430_section_type_flags): Likewise.
(msp430_expand_helper): Likewise.
* config/nios2/nios2.c (nios2_small_section_name_p): Likewise.
(nios2_valid_target_attribute_rec): Likewise.
* config/nvptx/mkoffload.c (process): Likewise.
(STR): Likewise.
* config/pa/som.h: Likewise.
* config/pdp11/pdp11.c (pdp11_output_ident): Likewise.
* config/riscv/riscv.c (riscv_elf_select_rtx_section): Likewise.
* config/rs6000/rs6000.c (VTABLE_NAME_P): Likewise.
(rs6000_inner_target_options): Likewise.
* config/s390/driver-native.c (s390_host_detect_local_cpu): Likewise.
* config/sparc/driver-sparc.c (host_detect_local_cpu): Likewise.
* config/vax/vax.c (vax_output_int_move): Likewise.
* config/vms/vms-ld.c (startswith): Likewise.
(process_args): Likewise.
(main): Likewise.
* config/vms/vms.c: Likewise.
---
 gcc/common/config/aarch64/aarch64-common.c|   2 +-
 gcc/common/config/bfin/bfin-common.c  |   2 +-
 gcc/common/config/riscv/riscv-common.c|   4 +-
 .../aarch64/aarch64-sve-builtins-shapes.cc|   4 +-
 gcc/config/aarch64/aarch64.c  |   2 +-
 gcc/config/alpha/alpha.c  |   8 +-
 gcc/config/arm/aarch-common.c |   2 +-
 gcc/config/arm/arm.c  |   8 +-
 gcc/config/arm/driver-arm.c   |   4 +-
 gcc/config/avr/avr.c  |  25 ++--
 gcc/config/c6x/c6x.c  |  14 +-
 gcc/config/darwin-c.c |   9 +-
 gcc/config/darwin.c   | 141 +-
 gcc/config/frv/frv.c  |  16 +-
 gcc/config/gcn/mkoffload.c|  10 +-
 gcc/config/i386/i386-builtins.c   |   2 +-
 gcc/config/i386/i386-options.c|   2 +-
 gcc/config/i386/i386.c|   7 +-
 gcc/config/i386/intelmic-mkoffload.c  |   4 +-
 

[PATCH 2/3] LTO plugin: use startswith function.

2021-04-21 Thread Martin Liska

lto-plugin/ChangeLog:

* lto-plugin.c (LTO_SEGMENT_NAME): Remove.
(LTO_SYMTAB_PREFIX): Likewise.
(LTO_SYMTAB_PREFIX_LEN): Likewise.
(LTO_SYMTAB_EXT_PREFIX): Likewise.
(LTO_SYMTAB_EXT_PREFIX_LEN): Likewise.
(LTO_LTO_PREFIX): Likewise.
(LTO_LTO_PREFIX_LEN): Likewise.
(OFFLOAD_SECTION): Likewise.
(OFFLOAD_SECTION_LEN): Likewise.
(startswith): New function.
(all_symbols_read_handler): Use it.
(process_symtab): Likewise.
(process_symtab_extension): Likewise.
(process_offload_section): Likewise.
(process_option): Likewise.
---
 lto-plugin/lto-plugin.c | 29 +
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 32478f070e8..cd57ebca677 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -89,16 +89,13 @@ along with this program; see the file COPYING3.  If not see
 
 #define LTO_SEGMENT_NAME "__GNU_LTO"
 
-/* LTO magic section name.  */
+/* Return true if STR string starts with PREFIX.  */
 
-#define LTO_SYMTAB_PREFIX	".gnu.lto_.symtab"
-#define LTO_SYMTAB_PREFIX_LEN	(sizeof (LTO_SYMTAB_PREFIX) - 1)
-#define LTO_SYMTAB_EXT_PREFIX	".gnu.lto_.ext_symtab"
-#define LTO_SYMTAB_EXT_PREFIX_LEN   (sizeof (LTO_SYMTAB_EXT_PREFIX) - 1)
-#define LTO_LTO_PREFIX		".gnu.lto_.lto"
-#define LTO_LTO_PREFIX_LEN	(sizeof (LTO_LTO_PREFIX) - 1)
-#define OFFLOAD_SECTION		".gnu.offload_lto_.opts"
-#define OFFLOAD_SECTION_LEN	(sizeof (OFFLOAD_SECTION) - 1)
+static inline bool
+startswith (const char *str, const char *prefix)
+{
+  return strncmp (str, prefix, strlen (prefix)) == 0;
+}
 
 /* The part of the symbol table the plugin has to keep track of. Note that we
must keep SYMS until all_symbols_read is called to give the linker time to
@@ -832,7 +829,7 @@ all_symbols_read_handler (void)
   unsigned int i;
   for (i = 0; i < num_pass_through_items; i++)
 {
-  if (strncmp (pass_through_items[i], "-l", 2) == 0)
+	  if (startswith (pass_through_items[i], "-l"))
 add_input_library (pass_through_items[i] + 2);
   else
 add_input_file (pass_through_items[i]);
@@ -1022,7 +1019,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
   char *s;
   char *secdatastart, *secdata;
 
-  if (strncmp (name, LTO_SYMTAB_PREFIX, LTO_SYMTAB_PREFIX_LEN) != 0)
+  if (!startswith (name, ".gnu.lto_.symtab"))
 return 1;
 
   s = strrchr (name, '.');
@@ -1074,7 +1071,7 @@ process_symtab_extension (void *data, const char *name, off_t offset,
   char *s;
   char *secdatastart, *secdata;
 
-  if (strncmp (name, LTO_SYMTAB_EXT_PREFIX, LTO_SYMTAB_EXT_PREFIX_LEN) != 0)
+  if (!startswith (name, ".gnu.lto_.ext_symtab"))
 return 1;
 
   s = strrchr (name, '.');
@@ -1122,7 +1119,7 @@ err:
 static int
 process_offload_section (void *data, const char *name, off_t offset, off_t len)
 {
-  if (!strncmp (name, OFFLOAD_SECTION, OFFLOAD_SECTION_LEN))
+  if (startswith (name, ".gnu.offload_lto_.opts"))
 {
   struct plugin_objfile *obj = (struct plugin_objfile *) data;
   obj->offload = 1;
@@ -1325,7 +1322,7 @@ process_option (const char *option)
 save_temps = true;
   else if (strcmp (option, "-nop") == 0)
 nop = 1;
-  else if (!strncmp (option, "-pass-through=", strlen("-pass-through=")))
+  else if (startswith (option, "-pass-through="))
 {
   num_pass_through_items++;
   pass_through_items = xrealloc (pass_through_items,
@@ -1333,7 +1330,7 @@ process_option (const char *option)
   pass_through_items[num_pass_through_items - 1] =
   xstrdup (option + strlen ("-pass-through="));
 }
-  else if (!strncmp (option, "-sym-style=", sizeof ("-sym-style=") - 1))
+  else if (startswith (option, "-sym-style="))
 {
   switch (option[sizeof ("-sym-style=") - 1])
 	{
@@ -1356,7 +1353,7 @@ process_option (const char *option)
   size = lto_wrapper_num_args * sizeof (char *);
   lto_wrapper_argv = (char **) xrealloc (lto_wrapper_argv, size);
   lto_wrapper_argv[lto_wrapper_num_args - 1] = opt;
-  if (strncmp (option, "-fresolution=", sizeof ("-fresolution=") - 1) == 0)
+  if (startswith (option, "-fresolution="))
 	resolution_file = opt + sizeof ("-fresolution=") - 1;
 }
   save_temps = save_temps || debug;


[PATCH 0/3] Come up with startswith function

2021-04-21 Thread Martin Liska
The patchset is tested on x86_64-linux-gnu and I was able to build
all cross-compilers.

Ready to be installed to master once GCC 11.1 is released?
Thanks,
Martin

Martin Liska (3):
  Come up with startswith function.
  LTO plugin: use startswith function.
  Use startswith in targets.

 gcc/ada/adadecode.c   |  14 +-
 gcc/ada/gcc-interface/utils.c |   3 +-
 gcc/ada/init.c|   8 +-
 gcc/analyzer/sm-file.cc   |   5 +-
 gcc/builtins.c|  10 +-
 gcc/c-family/c-ada-spec.c |   8 +-
 gcc/c-family/c-common.c   |   5 +-
 gcc/c-family/c-format.c   |  20 +--
 gcc/c/c-aux-info.c|   4 +-
 gcc/c/c-typeck.c  |   4 +-
 gcc/c/gimple-parser.c |   2 +-
 gcc/collect2.c|  48 +++---
 gcc/common/config/aarch64/aarch64-common.c|   2 +-
 gcc/common/config/bfin/bfin-common.c  |   2 +-
 gcc/common/config/riscv/riscv-common.c|   4 +-
 .../aarch64/aarch64-sve-builtins-shapes.cc|   4 +-
 gcc/config/aarch64/aarch64.c  |   2 +-
 gcc/config/alpha/alpha.c  |   8 +-
 gcc/config/arm/aarch-common.c |   2 +-
 gcc/config/arm/arm.c  |   8 +-
 gcc/config/arm/driver-arm.c   |   4 +-
 gcc/config/avr/avr.c  |  25 ++--
 gcc/config/c6x/c6x.c  |  14 +-
 gcc/config/darwin-c.c |   9 +-
 gcc/config/darwin.c   | 141 +-
 gcc/config/frv/frv.c  |  16 +-
 gcc/config/gcn/mkoffload.c|  10 +-
 gcc/config/i386/i386-builtins.c   |   2 +-
 gcc/config/i386/i386-options.c|   2 +-
 gcc/config/i386/i386.c|   7 +-
 gcc/config/i386/intelmic-mkoffload.c  |   4 +-
 gcc/config/i386/winnt.c   |   5 +-
 gcc/config/ia64/ia64.c|  20 +--
 gcc/config/mips/driver-native.c   |   2 +-
 gcc/config/mips/mips.c|  10 +-
 gcc/config/msp430/msp430.c|  13 +-
 gcc/config/nios2/nios2.c  |  13 +-
 gcc/config/nvptx/mkoffload.c  |  10 +-
 gcc/config/pa/som.h   |  13 +-
 gcc/config/pdp11/pdp11.c  |   2 +-
 gcc/config/riscv/riscv.c  |   2 +-
 gcc/config/rs6000/rs6000.c|  18 +--
 gcc/config/s390/driver-native.c   |  12 +-
 gcc/config/sparc/driver-sparc.c   |   2 +-
 gcc/config/vax/vax.c  |   8 +-
 gcc/config/vms/vms-ld.c   |  22 ++-
 gcc/config/vms/vms.c  |   2 +-
 gcc/coverage.c|   7 +-
 gcc/cp/decl.c |  15 +-
 gcc/cp/error.c|   2 +-
 gcc/cp/mangle.c   |  11 +-
 gcc/cp/parser.c   |   7 +-
 gcc/cp/pt.c   |   5 +-
 gcc/d/d-builtins.cc   |   3 +-
 gcc/d/dmd/dinterpret.c|   2 +-
 gcc/d/dmd/dmangle.c   |   2 +-
 gcc/d/dmd/hdrgen.c|   2 +-
 gcc/d/dmd/identifier.c|   6 +-
 gcc/dwarf2out.c   |  14 +-
 gcc/fortran/decl.c|   4 +-
 gcc/fortran/gfortran.h|   4 -
 gcc/fortran/module.c  |  10 +-
 gcc/fortran/options.c |   2 +-
 gcc/fortran/primary.c |   6 +-
 gcc/fortran/trans-decl.c  |   2 +-
 gcc/fortran/trans-expr.c  |   2 +-
 gcc/fortran/trans-intrinsic.c |  22 +--
 gcc/gcc-ar.c  |   2 +-
 gcc/gcc.c |  14 +-
 gcc/genattrtab.c  |   8 +-
 gcc/gencfn-macros.c   |   2 +-
 gcc/gengtype.c|   8 +-
 gcc/genmatch.c|   8 +-
 gcc/genoutput.c   |   2 +-
 gcc/go/gofrontend/runtime.cc  |   2 +-
 gcc/incpath.c |   2 +-
 gcc/langhooks.c   |   8 +-
 gcc/lto-wrapper.c |   3 +-
 gcc/objc/objc-act.c   |   2 +-
 gcc/objc/objc-encoding.c  |   2 +-
 gcc/objc/objc-next-runtime-abi-02.c   |   2 +-
 gcc/omp-general.c |   2 +-
 gcc/omp-low.c |   2 +-
 gcc/opts-common.c

[PATCH 1/2] IPA symver: allow multiple symvers for a definition

2020-08-25 Thread Martin Liska

gcc/ChangeLog:

* cgraphunit.c (process_symver_attribute): Allow multiple
symver attributes for one symbol.
* doc/extend.texi: Document the change.

gcc/testsuite/ChangeLog:

* lib/target-supports-dg.exp: Add dg-require-symver.
* lib/target-supports.exp: Likewise.
* gcc.dg/ipa/symver1.c: New test.
---
 gcc/cgraphunit.c | 143 ---
 gcc/doc/extend.texi  |  10 +-
 gcc/testsuite/gcc.dg/ipa/symver1.c   |  11 ++
 gcc/testsuite/lib/target-supports-dg.exp |  10 ++
 gcc/testsuite/lib/target-supports.exp|  12 ++
 5 files changed, 110 insertions(+), 76 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/symver1.c

diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 0b1009d0dea..fa3aec79a48 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -720,80 +720,81 @@ process_symver_attribute (symtab_node *n)
 {
   tree value = lookup_attribute ("symver", DECL_ATTRIBUTES (n->decl));
 
-  if (!value)
-return;
-  if (lookup_attribute ("symver", TREE_CHAIN (value)))
+  for (; value != NULL; value = TREE_CHAIN (value))
 {
-  error_at (DECL_SOURCE_LOCATION (n->decl),
-		"multiple versions for one symbol");
-  return;
-}
-  tree symver = get_identifier_with_length
-		  (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (value))),
-		   TREE_STRING_LENGTH (TREE_VALUE (TREE_VALUE (value;
-  symtab_node *def = symtab_node::get_for_asmname (symver);
+  /* Starting from bintuils 2.35 gas supports:
+	  # Assign foo to bar@V1 and baz@V2.
+	  .symver foo, bar@V1
+	  .symver foo, baz@V2
+  */
+
+  tree symver = get_identifier_with_length
+	(TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (value))),
+	 TREE_STRING_LENGTH (TREE_VALUE (TREE_VALUE (value;
+  symtab_node *def = symtab_node::get_for_asmname (symver);
+
+  if (def)
+	{
+	  error_at (DECL_SOURCE_LOCATION (n->decl),
+		"duplicate definition of a symbol version");
+	  inform (DECL_SOURCE_LOCATION (def->decl),
+		  "same version was previously defined here");
+	  return;
+	}
+  if (!n->definition)
+	{
+	  error_at (DECL_SOURCE_LOCATION (n->decl),
+		"symbol needs to be defined to have a version");
+	  return;
+	}
+  if (DECL_COMMON (n->decl))
+	{
+	  error_at (DECL_SOURCE_LOCATION (n->decl),
+		"common symbol cannot be versioned");
+	  return;
+	}
+  if (DECL_COMDAT (n->decl))
+	{
+	  error_at (DECL_SOURCE_LOCATION (n->decl),
+		"comdat symbol cannot be versioned");
+	  return;
+	}
+  if (n->weakref)
+	{
+	  error_at (DECL_SOURCE_LOCATION (n->decl),
+		"% cannot be versioned");
+	  return;
+	}
+  if (!TREE_PUBLIC (n->decl))
+	{
+	  error_at (DECL_SOURCE_LOCATION (n->decl),
+		"versioned symbol must be public");
+	  return;
+	}
+  if (DECL_VISIBILITY (n->decl) != VISIBILITY_DEFAULT)
+	{
+	  error_at (DECL_SOURCE_LOCATION (n->decl),
+		"versioned symbol must have default visibility");
+	  return;
+	}
 
-  if (def)
-{
-  error_at (DECL_SOURCE_LOCATION (n->decl),
-		"duplicate definition of a symbol version");
-  inform (DECL_SOURCE_LOCATION (def->decl),
-	  "same version was previously defined here");
-  return;
-}
-  if (!n->definition)
-{
-  error_at (DECL_SOURCE_LOCATION (n->decl),
-		"symbol needs to be defined to have a version");
-  return;
-}
-  if (DECL_COMMON (n->decl))
-{
-  error_at (DECL_SOURCE_LOCATION (n->decl),
-		"common symbol cannot be versioned");
-  return;
-}
-  if (DECL_COMDAT (n->decl))
-{
-  error_at (DECL_SOURCE_LOCATION (n->decl),
-		"comdat symbol cannot be versioned");
-  return;
-}
-  if (n->weakref)
-{
-  error_at (DECL_SOURCE_LOCATION (n->decl),
-		"% cannot be versioned");
-  return;
+  /* Create new symbol table entry representing the version.  */
+  tree new_decl = copy_node (n->decl);
+
+  DECL_INITIAL (new_decl) = NULL_TREE;
+  if (TREE_CODE (new_decl) == FUNCTION_DECL)
+	DECL_STRUCT_FUNCTION (new_decl) = NULL;
+  SET_DECL_ASSEMBLER_NAME (new_decl, symver);
+  TREE_PUBLIC (new_decl) = 1;
+  DECL_ATTRIBUTES (new_decl) = NULL;
+
+  symtab_node *symver_node = symtab_node::get_create (new_decl);
+  symver_node->alias = true;
+  symver_node->definition = true;
+  symver_node->symver = true;
+  symver_node->create_reference (n, IPA_REF_ALIAS, NULL);
+  symver_node->analyzed = true;
 }
-  if (!TREE_PUBLIC (n->decl))
-{
-  error_at (DECL_SOURCE_LOCATION (n->decl),
-		"versioned symbol must be public");
-  return;
-}
-  if (DECL_VISIBILITY (n->decl) != VISIBILITY_DEFAULT)
-{
-  error_at (DECL_SOURCE_LOCATION (n->decl),
-		"versioned symbol must have default visibility");
-  return;
-}
-
-  /* Create new symbol table entry representing the version.  */
-  tree new_decl = copy_node (n->decl);
-
-  DECL_INITIAL (new_decl) = NULL_TREE;
-  if (TREE_CODE (new_decl) == 

[PATCH 2/2] IPA symver: support visibility and static symbols.

2020-08-25 Thread Martin Liska

gcc/ChangeLog:

* cgraphunit.c (process_symver_attribute): Remove checks that
are not needed now.
(cgraph_node::assemble_thunks_and_aliases): Change second
argument to decl.
* config/elfos.h (ASM_OUTPUT_SYMVER_DIRECTIVE): Add new
VISIBILITY parameter.
* doc/extend.texi: Document that .symver supports visibility.
* symtab.c (symtab_node::verify_base): Remove checks that
are not needed now.
* varasm.c (do_assemble_symver): Detect visibility .symver
directive argument.
* varpool.c (varpool_node::assemble_aliases): Change second
argument to decl.

gcc/testsuite/ChangeLog:

* gcc.dg/ipa/symver2.c: New test.
* gcc.dg/ipa/symver3.c: New test.
---
 gcc/cgraphunit.c   | 15 +--
 gcc/config/elfos.h | 20 +++-
 gcc/doc/extend.texi|  3 +--
 gcc/symtab.c   | 16 
 gcc/testsuite/gcc.dg/ipa/symver2.c |  9 +
 gcc/testsuite/gcc.dg/ipa/symver3.c | 13 +
 gcc/varasm.c   | 12 ++--
 gcc/varpool.c  |  3 +--
 8 files changed, 46 insertions(+), 45 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/symver2.c
 create mode 100644 gcc/testsuite/gcc.dg/ipa/symver3.c

diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index fa3aec79a48..c85d3482c8b 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -765,18 +765,6 @@ process_symver_attribute (symtab_node *n)
 		"% cannot be versioned");
 	  return;
 	}
-  if (!TREE_PUBLIC (n->decl))
-	{
-	  error_at (DECL_SOURCE_LOCATION (n->decl),
-		"versioned symbol must be public");
-	  return;
-	}
-  if (DECL_VISIBILITY (n->decl) != VISIBILITY_DEFAULT)
-	{
-	  error_at (DECL_SOURCE_LOCATION (n->decl),
-		"versioned symbol must have default visibility");
-	  return;
-	}
 
   /* Create new symbol table entry representing the version.  */
   tree new_decl = copy_node (n->decl);
@@ -2239,8 +2227,7 @@ cgraph_node::assemble_thunks_and_aliases (void)
 	 of buffering it in same alias pairs.  */
 	  TREE_ASM_WRITTEN (decl) = 1;
 	  if (alias->symver)
-	do_assemble_symver (alias->decl,
-DECL_ASSEMBLER_NAME (decl));
+	do_assemble_symver (alias->decl, decl);
 	  else
 	do_assemble_alias (alias->decl,
 			   DECL_ASSEMBLER_NAME (decl));
diff --git a/gcc/config/elfos.h b/gcc/config/elfos.h
index 74a3eafda6b..6c9b73320b9 100644
--- a/gcc/config/elfos.h
+++ b/gcc/config/elfos.h
@@ -248,15 +248,17 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 }	\
   while (0)
 
-#define ASM_OUTPUT_SYMVER_DIRECTIVE(FILE, NAME, NAME2)		\
-  do\
-{\
-  fputs ("\t.symver\t", (FILE));\
-  assemble_name ((FILE), (NAME));\
-  fputs (", ", (FILE));	\
-  assemble_name ((FILE), (NAME2));\
-  fputc ('\n', (FILE));	\
-}\
+#define ASM_OUTPUT_SYMVER_DIRECTIVE(FILE, NAME, NAME2, VISIBILITY)  \
+  do\
+{\
+  fputs ("\t.symver\t", (FILE));\
+  assemble_name ((FILE), (NAME));\
+  fputs (", ", (FILE));	\
+  assemble_name ((FILE), (NAME2));\
+  if (visibility != NULL)	\
+	fprintf ((FILE), ", %s", (VISIBILITY));			\
+  fputc ('\n', (FILE));	\
+}\
   while (0)
 
 /* The following macro defines the format used to output the second
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 97ae1ee0843..22e62f36714 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -3729,8 +3729,7 @@ On ELF targets this attribute creates a symbol version.  The @var{name2} part
 of the parameter is the actual name of the symbol by which it will be
 externally referenced.  The @code{nodename} portion should be the name of a
 node specified in the version script supplied to the linker when building a
-shared library.  Versioned symbol must be defined and must be exported with
-default visibility.
+shared library.
 
 @smallexample
 __attribute__ ((__symver__ ("foo@@VERS_1"))) int
diff --git a/gcc/symtab.c b/gcc/symtab.c
index d7dfbb676df..51628fe625f 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -1178,22 +1178,6 @@ symtab_node::verify_base (void)
   error ("node is symver but not alias");
   error_found = true;
 }
-  /* Limitation of gas requires us to output targets of symver aliases as
- global symbols.  This is binutils PR 25295.  */
-  if (symver
-  && (!TREE_PUBLIC (get_alias_target ()->decl)
-	  || DECL_VISIBILITY (get_alias_target ()->decl) != VISIBILITY_DEFAULT))
-{
-  error ("symver target is not exported with default visibility");
-  error_found = true;
-}
-  if (symver
-  && (!TREE_PUBLIC (decl)
-	  || DECL_VISIBILITY (decl) != VISIBILITY_DEFAULT))
-{
-  error ("symver is not exported with default visibility");
-  

[PATCH 0/2] symver: extend functionality

2020-08-25 Thread Martin Liska
Hey.

Since the bintuils release 2.35, we can now support new .symver syntax added in:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6914be53bd662eefd979d0c82d2e20e108c4ee66

Patch survives bootstrap and regression tests.
Thoughts?
Martin

Martin Liska (2):
  IPA symver: allow multiple symvers for a definition
  IPA symver: support visibility and static symbols.

 gcc/cgraphunit.c | 134 +++
 gcc/config/elfos.h   |  20 ++--
 gcc/doc/extend.texi  |  13 +--
 gcc/symtab.c |  16 ---
 gcc/testsuite/gcc.dg/ipa/symver1.c   |  11 ++
 gcc/testsuite/gcc.dg/ipa/symver2.c   |   9 ++
 gcc/testsuite/gcc.dg/ipa/symver3.c   |  13 +++
 gcc/testsuite/lib/target-supports-dg.exp |  10 ++
 gcc/testsuite/lib/target-supports.exp|  12 ++
 gcc/varasm.c |  12 +-
 gcc/varpool.c|   3 +-
 11 files changed, 144 insertions(+), 109 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/symver1.c
 create mode 100644 gcc/testsuite/gcc.dg/ipa/symver2.c
 create mode 100644 gcc/testsuite/gcc.dg/ipa/symver3.c

-- 
2.28.0



[PATCH] Update merge.sh to reflect usage of git.

2020-05-26 Thread Martin Liska
After switching to GIT, we should use it in libsanitizer
merge script. I'll do merge from master as soon as
PR95311 gets fixed.

I'm going to install the patch.

libsanitizer/ChangeLog:

* LOCAL_PATCHES: Use git hash instead of SVN id.
* merge.sh: Use git instead of VCS.  Update paths
relative to upstream git repository.
---
 libsanitizer/LOCAL_PATCHES |  2 +-
 libsanitizer/merge.sh  | 10 --
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/libsanitizer/LOCAL_PATCHES b/libsanitizer/LOCAL_PATCHES
index 292b7a6e489..7732de3d436 100644
--- a/libsanitizer/LOCAL_PATCHES
+++ b/libsanitizer/LOCAL_PATCHES
@@ -1 +1 @@
-r277910
+21bb1625bd4f183984223ce31bd03ba47ed62f27
diff --git a/libsanitizer/merge.sh b/libsanitizer/merge.sh
index dfa7bf3d196..3f4f1629a22 100755
--- a/libsanitizer/merge.sh
+++ b/libsanitizer/merge.sh
@@ -4,8 +4,6 @@
 
 # This script merges libsanitizer sources from upstream.
 
-VCS=${1:-svn}
-
 get_upstream() {
   rm -rf upstream
   git clone https://github.com/llvm/llvm-project.git upstream
@@ -33,7 +31,7 @@ change_comment_headers() {
 # This function merges changes from the directory upstream_path to
 # the directory  local_path.
 merge() {
-  upstream_path=upstream/$1
+  upstream_path=upstream/compiler-rt/$1
   local_path=$2
   change_comment_headers $upstream_path
   echo MERGE: $upstream_path
@@ -47,10 +45,10 @@ merge() {
 elif [ -f $upstream_path/$f ]; then
   echo "FOUND IN UPSTREAM :" $f
   cp -v $upstream_path/$f $local_path
-  $VCS add $local_path/$f
+  git add $local_path/$f
 elif [ -f $local_path/$f ]; then
   echo "FOUND IN LOCAL:" $f
-  $VCS rm $local_path/$f
+  git rm $local_path/$f
 fi
   done
 
@@ -76,7 +74,7 @@ merge lib/ubsan ubsan
 
 # Need to merge lib/builtins/assembly.h file:
 mkdir -p builtins
-cp -v upstream/lib/builtins/assembly.h builtins/assembly.h
+cp -v upstream/compiler-rt/lib/builtins/assembly.h builtins/assembly.h
 
 rm -rf upstream
 
-- 
2.26.2



[PATCH 3/3] Remove __gcov_flush.

2020-04-03 Thread Martin Liska

gcc/ChangeLog:

2020-04-03  Martin Liska  

PR gcov-profile/93623
* tree-cfg.c (stmt_can_terminate_bb_p): Update comment to reflect
reality.

libgcc/ChangeLog:

2020-04-03  Martin Liska  

PR gcov-profile/93623
* Makefile.in: Remove __gcov_flush.
* gcov.h (__gcov_flush): Remove.
* libgcov-interface.c (__gcov_flush): Remove.
(init_mx): Use renamed mutex.
(__gcov_lock): Likewise.
(__gcov_unlock): Likewise.
(__gcov_fork): Likewise.
(__gcov_flush): Remove.
---
 gcc/tree-cfg.c |  4 ++--
 libgcc/Makefile.in |  2 +-
 libgcc/gcov.h  |  5 -
 libgcc/libgcov-interface.c | 36 +++-
 4 files changed, 10 insertions(+), 37 deletions(-)

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index e99fb9ff5d1..b21ef0eee37 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -8439,8 +8439,8 @@ stmt_can_terminate_bb_p (gimple *t)
   && (call_flags & ECF_NOTHROW)
   && !(call_flags & ECF_RETURNS_TWICE)
   /* fork() doesn't really return twice, but the effect of
- wrapping it in __gcov_fork() which calls __gcov_flush()
-	 and clears the counters before forking has the same
+	 wrapping it in __gcov_fork() which calls __gcov_dump() and
+	 __gcov_reset() and clears the counters before forking has the same
 	 effect as returning twice.  Force a fake edge.  */
   && !fndecl_built_in_p (fndecl, BUILT_IN_FORK))
 return false;
diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index e6ed153abbc..5c50f9fe4df 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -904,7 +904,7 @@ LIBGCOV_PROFILER = _gcov_interval_profiler\
 	_gcov_ior_profiler_atomic	\
 	_gcov_indirect_call_profiler_v4	\
 	_gcov_time_profiler
-LIBGCOV_INTERFACE = _gcov_dump _gcov_flush _gcov_fork			\
+LIBGCOV_INTERFACE = _gcov_dump _gcov_fork\
 	_gcov_execl _gcov_execlp	\
 	_gcov_execle _gcov_execv _gcov_execvp _gcov_execve _gcov_reset  \
 	_gcov_lock_unlock
diff --git a/libgcc/gcov.h b/libgcc/gcov.h
index f1581914dde..0e3eed31032 100644
--- a/libgcc/gcov.h
+++ b/libgcc/gcov.h
@@ -33,9 +33,4 @@ extern void __gcov_reset (void);
 
 extern void __gcov_dump (void);
 
-/* Write profile information to a file and reset counters to zero.
-   The function does operations under a mutex.  */
-
-extern void __gcov_flush (void);
-
 #endif /* GCC_GCOV_H */
diff --git a/libgcc/libgcov-interface.c b/libgcc/libgcov-interface.c
index 855e8612018..3a8a5bf44b8 100644
--- a/libgcc/libgcov-interface.c
+++ b/libgcc/libgcov-interface.c
@@ -28,10 +28,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #if defined(inhibit_libc)
 
-#ifdef L_gcov_flush
-void __gcov_flush (void) {}
-#endif
-
 #ifdef L_gcov_reset
 void __gcov_reset (void) {}
 #endif
@@ -42,19 +38,19 @@ void __gcov_dump (void) {}
 
 #else
 
-extern __gthread_mutex_t __gcov_flush_mx ATTRIBUTE_HIDDEN;
+extern __gthread_mutex_t __gcov_mx ATTRIBUTE_HIDDEN;
 
 #ifdef L_gcov_lock_unlock
 #ifdef __GTHREAD_MUTEX_INIT
-__gthread_mutex_t __gcov_flush_mx = __GTHREAD_MUTEX_INIT;
+__gthread_mutex_t __gcov_mx = __GTHREAD_MUTEX_INIT;
 #define init_mx_once()
 #else
-__gthread_mutex_t __gcov_flush_mx;
+__gthread_mutex_t __gcov_mx;
 
 static void
 init_mx (void)
 {
-  __GTHREAD_MUTEX_INIT_FUNCTION (&__gcov_flush_mx);
+  __GTHREAD_MUTEX_INIT_FUNCTION (&__gcov_mx);
 }
 
 static void
@@ -71,7 +67,7 @@ void
 __gcov_lock (void)
 {
   init_mx_once ();
-  __gthread_mutex_lock (&__gcov_flush_mx);
+  __gthread_mutex_lock (&__gcov_mx);
 }
 
 /* Unlock critical section for __gcov_dump and __gcov_reset functions.  */
@@ -79,28 +75,10 @@ __gcov_lock (void)
 void
 __gcov_unlock (void)
 {
-  __gthread_mutex_unlock (&__gcov_flush_mx);
+  __gthread_mutex_unlock (&__gcov_mx);
 }
 #endif
 
-#ifdef L_gcov_flush
-/* Called before fork or exec - write out profile information gathered so
-   far and reset it to zero.  This avoids duplication or loss of the
-   profile information gathered so far.  */
-
-void
-__gcov_flush (void)
-{
-  __gcov_lock ();
-
-  __gcov_dump_int ();
-  __gcov_reset_int ();
-
-  __gcov_unlock ();
-}
-
-#endif /* L_gcov_flush */
-
 #ifdef L_gcov_reset
 
 /* Reset all counters to zero.  */
@@ -207,7 +185,7 @@ __gcov_fork (void)
   pid = fork ();
   if (pid == 0)
 {
-  __GTHREAD_MUTEX_INIT_FUNCTION (&__gcov_flush_mx);
+  __GTHREAD_MUTEX_INIT_FUNCTION (&__gcov_mx);
   /* We do not need locking as we are the only thread in the child.  */
   __gcov_reset_int ();
 }


[PATCH 2/3] Use __gcov_dump and __gcov_reset in execv and fork context.

2020-04-03 Thread Martin Liska

libgcc/ChangeLog:

2020-04-03  Martin Liska  

PR gcov-profile/93623
* libgcov-interface.c (__gcov_fork): Do not flush
and reset only in child process.
(__gcov_execl): Dump counters only and reset them
only if exec* fails.
(__gcov_execlp): Likewise.
(__gcov_execle): Likewise.
(__gcov_execv): Likewise.
(__gcov_execvp): Likewise.
(__gcov_execve): Likewise.
---
 libgcc/libgcov-interface.c | 59 +++---
 1 file changed, 43 insertions(+), 16 deletions(-)

diff --git a/libgcc/libgcov-interface.c b/libgcc/libgcov-interface.c
index a8054edba57..855e8612018 100644
--- a/libgcc/libgcov-interface.c
+++ b/libgcc/libgcov-interface.c
@@ -197,17 +197,20 @@ __gcov_dump (void)
 #endif /* L_gcov_dump */
 
 #ifdef L_gcov_fork
-/* A wrapper for the fork function.  Flushes the accumulated profiling data, so
-   that they are not counted twice.  */
+/* A wrapper for the fork function.  We reset counters in the child
+   so that they are not counted twice.  */
 
 pid_t
 __gcov_fork (void)
 {
   pid_t pid;
-  __gcov_flush ();
   pid = fork ();
   if (pid == 0)
-__GTHREAD_MUTEX_INIT_FUNCTION (&__gcov_flush_mx);
+{
+  __GTHREAD_MUTEX_INIT_FUNCTION (&__gcov_flush_mx);
+  /* We do not need locking as we are the only thread in the child.  */
+  __gcov_reset_int ();
+}
   return pid;
 }
 #endif
@@ -223,7 +226,8 @@ __gcov_execl (const char *path, char *arg, ...)
   unsigned i, length;
   char **args;
 
-  __gcov_flush ();
+  /* Dump counters only, they will be lost after exec.  */
+  __gcov_dump ();
 
   va_start (ap, arg);
   va_copy (aq, ap);
@@ -239,7 +243,10 @@ __gcov_execl (const char *path, char *arg, ...)
 args[i] = va_arg (aq, char *);
   va_end (aq);
 
-  return execv (path, args);
+  int ret = execv (path, args);
+  /* We reach this code only when execv fails, reset counter then here.  */
+  __gcov_reset ();
+  return ret;
 }
 #endif
 
@@ -254,7 +261,8 @@ __gcov_execlp (const char *path, char *arg, ...)
   unsigned i, length;
   char **args;
 
-  __gcov_flush ();
+  /* Dump counters only, they will be lost after exec.  */
+  __gcov_dump ();
 
   va_start (ap, arg);
   va_copy (aq, ap);
@@ -270,7 +278,10 @@ __gcov_execlp (const char *path, char *arg, ...)
 args[i] = va_arg (aq, char *);
   va_end (aq);
 
-  return execvp (path, args);
+  int ret = execvp (path, args);
+  /* We reach this code only when execv fails, reset counter then here.  */
+  __gcov_reset ();
+  return ret;
 }
 #endif
 
@@ -286,7 +297,8 @@ __gcov_execle (const char *path, char *arg, ...)
   char **args;
   char **envp;
 
-  __gcov_flush ();
+  /* Dump counters only, they will be lost after exec.  */
+  __gcov_dump ();
 
   va_start (ap, arg);
   va_copy (aq, ap);
@@ -303,7 +315,10 @@ __gcov_execle (const char *path, char *arg, ...)
   envp = va_arg (aq, char **);
   va_end (aq);
 
-  return execve (path, args, envp);
+  int ret = execve (path, args, envp);
+  /* We reach this code only when execv fails, reset counter then here.  */
+  __gcov_reset ();
+  return ret;
 }
 #endif
 
@@ -314,8 +329,12 @@ __gcov_execle (const char *path, char *arg, ...)
 int
 __gcov_execv (const char *path, char *const argv[])
 {
-  __gcov_flush ();
-  return execv (path, argv);
+  /* Dump counters only, they will be lost after exec.  */
+  __gcov_dump ();
+  int ret = execv (path, argv);
+  /* We reach this code only when execv fails, reset counter then here.  */
+  __gcov_reset ();
+  return ret;
 }
 #endif
 
@@ -326,8 +345,12 @@ __gcov_execv (const char *path, char *const argv[])
 int
 __gcov_execvp (const char *path, char *const argv[])
 {
-  __gcov_flush ();
-  return execvp (path, argv);
+  /* Dump counters only, they will be lost after exec.  */
+  __gcov_dump ();
+  int ret = execvp (path, argv);
+  /* We reach this code only when execv fails, reset counter then here.  */
+  __gcov_reset ();
+  return ret;
 }
 #endif
 
@@ -338,8 +361,12 @@ __gcov_execvp (const char *path, char *const argv[])
 int
 __gcov_execve (const char *path, char *const argv[], char *const envp[])
 {
-  __gcov_flush ();
-  return execve (path, argv, envp);
+  /* Dump counters only, they will be lost after exec.  */
+  __gcov_dump ();
+  int ret = execve (path, argv, envp);
+  /* We reach this code only when execv fails, reset counter then here.  */
+  __gcov_reset ();
+  return ret;
 }
 #endif
 #endif /* inhibit_libc */


[PATCH 1/3] Do locking for __gcov_dump and __gcov_reset as well.

2020-04-03 Thread Martin Liska

libgcc/ChangeLog:

2020-04-03  Martin Liska  

PR gcov-profile/93623
* Makefile.in: Add _gcov_lock_unlock to LIBGCOV_INTERFACE.
* libgcov-interface.c (ALIAS_void_fn): Remove.
(__gcov_lock): New.
(__gcov_unlock): New.
(__gcov_flush): Use __gcov_lock and __gcov_unlock.
(__gcov_reset): Likewise.
(__gcov_dump): Likewise.
* libgcov.h (__gcov_lock): New declaration.
(__gcov_unlock): Likewise.
---
 libgcc/Makefile.in |  3 +-
 libgcc/libgcov-interface.c | 59 --
 libgcc/libgcov.h   |  6 
 3 files changed, 52 insertions(+), 16 deletions(-)

diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index 851e7657d07..e6ed153abbc 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -906,7 +906,8 @@ LIBGCOV_PROFILER = _gcov_interval_profiler\
 	_gcov_time_profiler
 LIBGCOV_INTERFACE = _gcov_dump _gcov_flush _gcov_fork			\
 	_gcov_execl _gcov_execlp	\
-	_gcov_execle _gcov_execv _gcov_execvp _gcov_execve _gcov_reset
+	_gcov_execle _gcov_execv _gcov_execvp _gcov_execve _gcov_reset  \
+	_gcov_lock_unlock
 LIBGCOV_DRIVER = _gcov
 
 libgcov-merge-objects = $(patsubst %,%$(objext),$(LIBGCOV_MERGE))
diff --git a/libgcc/libgcov-interface.c b/libgcc/libgcov-interface.c
index 048b9029ff3..a8054edba57 100644
--- a/libgcc/libgcov-interface.c
+++ b/libgcc/libgcov-interface.c
@@ -42,18 +42,9 @@ void __gcov_dump (void) {}
 
 #else
 
-/* Some functions we want to bind in this dynamic object, but have an
-   overridable global alias.  Unfortunately not all targets support
-   aliases, so we just have a forwarding function.  That'll be tail
-   called, so the cost is a single jump instruction.*/
-
-#define ALIAS_void_fn(src,dst) \
-  void dst (void)	\
-  { src (); }
-
 extern __gthread_mutex_t __gcov_flush_mx ATTRIBUTE_HIDDEN;
 
-#ifdef L_gcov_flush
+#ifdef L_gcov_lock_unlock
 #ifdef __GTHREAD_MUTEX_INIT
 __gthread_mutex_t __gcov_flush_mx = __GTHREAD_MUTEX_INIT;
 #define init_mx_once()
@@ -74,6 +65,25 @@ init_mx_once (void)
 }
 #endif
 
+/* Lock critical section for __gcov_dump and __gcov_reset functions.  */
+
+void
+__gcov_lock (void)
+{
+  init_mx_once ();
+  __gthread_mutex_lock (&__gcov_flush_mx);
+}
+
+/* Unlock critical section for __gcov_dump and __gcov_reset functions.  */
+
+void
+__gcov_unlock (void)
+{
+  __gthread_mutex_unlock (&__gcov_flush_mx);
+}
+#endif
+
+#ifdef L_gcov_flush
 /* Called before fork or exec - write out profile information gathered so
far and reset it to zero.  This avoids duplication or loss of the
profile information gathered so far.  */
@@ -81,13 +91,12 @@ init_mx_once (void)
 void
 __gcov_flush (void)
 {
-  init_mx_once ();
-  __gthread_mutex_lock (&__gcov_flush_mx);
+  __gcov_lock ();
 
   __gcov_dump_int ();
   __gcov_reset_int ();
 
-  __gthread_mutex_unlock (&__gcov_flush_mx);
+  __gcov_unlock ();
 }
 
 #endif /* L_gcov_flush */
@@ -143,7 +152,17 @@ __gcov_reset_int (void)
 }
 }
 
-ALIAS_void_fn (__gcov_reset_int, __gcov_reset);
+/* Exported function __gcov_reset.  */
+
+void
+__gcov_reset (void)
+{
+  __gcov_lock ();
+
+  __gcov_reset_int ();
+
+  __gcov_unlock ();
+}
 
 #endif /* L_gcov_reset */
 
@@ -163,7 +182,17 @@ __gcov_dump_int (void)
 __gcov_dump_one (root);
 }
 
-ALIAS_void_fn (__gcov_dump_int, __gcov_dump);
+/* Exported function __gcov_dump.  */
+
+void
+__gcov_dump (void)
+{
+  __gcov_lock ();
+
+  __gcov_dump_int ();
+
+  __gcov_unlock ();
+}
 
 #endif /* L_gcov_dump */
 
diff --git a/libgcc/libgcov.h b/libgcc/libgcov.h
index 023293e05ec..104b80bdcbb 100644
--- a/libgcc/libgcov.h
+++ b/libgcc/libgcov.h
@@ -253,6 +253,12 @@ extern void __gcov_reset_int (void) ATTRIBUTE_HIDDEN;
 /* User function to enable early write of profile information so far.  */
 extern void __gcov_dump_int (void) ATTRIBUTE_HIDDEN;
 
+/* Lock critical section for __gcov_dump and __gcov_reset functions.  */
+extern void __gcov_lock (void) ATTRIBUTE_HIDDEN;
+
+/* Unlock critical section for __gcov_dump and __gcov_reset functions.  */
+extern void __gcov_unlock (void) ATTRIBUTE_HIDDEN;
+
 /* The merge function that just sums the counters.  */
 extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
 


[stage1][PATCH 0/3] __gcov_dump improvements

2020-04-03 Thread Martin Liska
Hi.

The following mini patch series improves:
- gcov run-time locking is used for user accessible __gcov_dump and 
__gcov_reset functions
- do not run __gcov_flush in fork, only __gcov_reset is called in child process
- gcov exec* wrappers dump counters and reset only if execv* fails

Patch can bootstrap on x86_64-linux-gnu and survives regression tests. 
I'll install the patch set in next stage1 if there are no objections.

Thanks,
Martin

Martin Liska (3):
  Do locking for __gcov_dump and __gcov_reset as well.
  Use __gcov_dump and __gcov_reset in execv and fork context.
  Remove __gcov_flush.

 gcc/tree-cfg.c |   4 +-
 libgcc/Makefile.in |   5 +-
 libgcc/gcov.h  |   5 --
 libgcc/libgcov-interface.c | 126 +++--
 libgcc/libgcov.h   |   6 ++
 5 files changed, 91 insertions(+), 55 deletions(-)

-- 
2.26.0



[PATCH 3/4] Put index check before use.

2020-02-06 Thread Martin Liska

liboffloadmic/ChangeLog:

2020-02-04  Martin Liska  

PR other/89860.
* runtime/offload_target.cpp: Put index check
before its use.
---
 liboffloadmic/runtime/offload_target.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/liboffloadmic/runtime/offload_target.cpp b/liboffloadmic/runtime/offload_target.cpp
index 8273faac13b..16ba4a32991 100644
--- a/liboffloadmic/runtime/offload_target.cpp
+++ b/liboffloadmic/runtime/offload_target.cpp
@@ -329,7 +329,7 @@ void OffloadDescriptor::merge_var_descs(
 }
 }
 // instead of m_vars[i].type.dst we will use m_vars_extra[i].type_dst
-if (m_vars[i].type.dst == c_extended_type && i < vars_total) {
+if (i < vars_total && m_vars[i].type.dst == c_extended_type) {
 VarDescExtendedType *etype =
 reinterpret_cast(vars[i].into);
 m_vars_extra[i].type_dst = etype->extended_type;


[PATCH 1/4] Remove 2 dead variables in bid_internal.h.

2020-02-06 Thread Martin Liska

libgcc/config/libbid/ChangeLog:

2020-02-04  Martin Liska  

PR libgcc/92565
* bid_internal.h (handle_UF_128_rem): Remove unused variable.
(handle_UF_128): Likewise.
---
 libgcc/config/libbid/bid_internal.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/libgcc/config/libbid/bid_internal.h b/libgcc/config/libbid/bid_internal.h
index cef36a9bb80..9baa098caac 100644
--- a/libgcc/config/libbid/bid_internal.h
+++ b/libgcc/config/libbid/bid_internal.h
@@ -1540,8 +1540,6 @@ handle_UF_128_rem (UINT128 * pres, UINT64 sgn, int expon, UINT128 CQ,
 __shr_128 (CQ, Qh, amount);
   }
 
-  expon = 0;
-
 #ifndef IEEE_ROUND_NEAREST_TIES_AWAY
 #ifndef IEEE_ROUND_NEAREST
   if (!(*prounding_mode))
@@ -1676,8 +1674,6 @@ handle_UF_128 (UINT128 * pres, UINT64 sgn, int expon, UINT128 CQ,
 __shr_128 (CQ, Qh, amount);
   }
 
-  expon = 0;
-
 #ifndef IEEE_ROUND_NEAREST_TIES_AWAY
 #ifndef IEEE_ROUND_NEAREST
   if (!(*prounding_mode))


[PATCH 4/4] Use const for template argument.

2020-02-06 Thread Martin Liska

libstdc++-v3/ChangeLog:

2020-02-04  Martin Liska  

PR c/92472.
* include/parallel/multiway_merge.h:
Use const for _Compare template argument.
---
 libstdc++-v3/include/parallel/multiway_merge.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/parallel/multiway_merge.h b/libstdc++-v3/include/parallel/multiway_merge.h
index 983c7b2bd9a..97a9ce0feb7 100644
--- a/libstdc++-v3/include/parallel/multiway_merge.h
+++ b/libstdc++-v3/include/parallel/multiway_merge.h
@@ -118,7 +118,7 @@ namespace __gnu_parallel
*  @return @c true if less. */
   friend bool
   operator<(_GuardedIterator<_RAIter, _Compare>& __bi1,
-		_GuardedIterator<_RAIter, _Compare>& __bi2)
+		_GuardedIterator<_RAIter, const _Compare>& __bi2)
   {
 	if (__bi1._M_current == __bi1._M_end)   // __bi1 is sup
 	  return __bi2._M_current == __bi2._M_end;  // __bi2 is not sup
@@ -188,7 +188,7 @@ namespace __gnu_parallel
*  @return @c true if less. */
   friend bool
   operator<(_UnguardedIterator<_RAIter, _Compare>& __bi1,
-		_UnguardedIterator<_RAIter, _Compare>& __bi2)
+		_UnguardedIterator<_RAIter, const _Compare>& __bi2)
   {
 	// Normal compare.
 	return (__bi1.__comp)(*__bi1, *__bi2);


[PATCH 2/4] Use const for some function arguments.

2020-02-06 Thread Martin Liska

gcc/ChangeLog:

2020-02-04  Martin Liska  

PR c/92472.
* alloc-pool.h: Use const for some arguments.
* bitmap.h: Likewise.
* mem-stats.h: Likewise.
* sese.h (get_entry_bb): Likewise.
(get_exit_bb): Likewise.
---
 gcc/alloc-pool.h | 2 +-
 gcc/bitmap.h | 2 +-
 gcc/mem-stats.h  | 4 ++--
 gcc/sese.h   | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/alloc-pool.h b/gcc/alloc-pool.h
index 1686a8b5f91..fd7194bfea4 100644
--- a/gcc/alloc-pool.h
+++ b/gcc/alloc-pool.h
@@ -60,7 +60,7 @@ public:
 
   /* Dump usage coupled to LOC location, where TOTAL is sum of all rows.  */
   inline void
-  dump (mem_location *loc, mem_usage ) const
+  dump (mem_location *loc, const mem_usage ) const
   {
 char *location_string = loc->to_string ();
 
diff --git a/gcc/bitmap.h b/gcc/bitmap.h
index d52fd5bb905..b481f4b2606 100644
--- a/gcc/bitmap.h
+++ b/gcc/bitmap.h
@@ -237,7 +237,7 @@ public:
 
   /* Dump usage coupled to LOC location, where TOTAL is sum of all rows.  */
   inline void
-  dump (mem_location *loc, mem_usage ) const
+  dump (mem_location *loc, const mem_usage ) const
   {
 char *location_string = loc->to_string ();
 
diff --git a/gcc/mem-stats.h b/gcc/mem-stats.h
index 21d038bb370..4a3177dd4fc 100644
--- a/gcc/mem-stats.h
+++ b/gcc/mem-stats.h
@@ -70,7 +70,7 @@ public:
 
   /* Return true if the memory location is equal to OTHER.  */
   int
-  equal (mem_location )
+  equal (const mem_location )
   {
 return m_filename == other.m_filename && m_function == other.m_function
   && m_line == other.m_line;
@@ -203,7 +203,7 @@ public:
 
   /* Dump usage coupled to LOC location, where TOTAL is sum of all rows.  */
   inline void
-  dump (mem_location *loc, mem_usage ) const
+  dump (mem_location *loc, const mem_usage ) const
   {
 char *location_string = loc->to_string ();
 
diff --git a/gcc/sese.h b/gcc/sese.h
index 8afea28b07e..74d3fe3cd8a 100644
--- a/gcc/sese.h
+++ b/gcc/sese.h
@@ -45,7 +45,7 @@ void dump_sese (const sese_l &);
 /* Get the entry of an sese S.  */
 
 static inline basic_block
-get_entry_bb (sese_l )
+get_entry_bb (const sese_l )
 {
   return s.entry->dest;
 }
@@ -53,7 +53,7 @@ get_entry_bb (sese_l )
 /* Get the exit of an sese S.  */
 
 static inline basic_block
-get_exit_bb (sese_l )
+get_exit_bb (const sese_l )
 {
   return s.exit->src;
 }


[PATCH 0/4] Fix various minor issues seen with cppcheck

2020-02-06 Thread Martin Liska
Hi.

The series is about small issues that were spotted with cppcheck
and where David Binderman suggested a patch.

It's probably a stage1 material?

Martin

Martin Liska (4):
  Remove 2 dead variables in bid_internal.h.
  Use const for some function arguments.
  Put index check before use.
  Use const for template argument.

 gcc/alloc-pool.h   | 2 +-
 gcc/bitmap.h   | 2 +-
 gcc/mem-stats.h| 4 ++--
 gcc/sese.h | 4 ++--
 libgcc/config/libbid/bid_internal.h| 4 
 liboffloadmic/runtime/offload_target.cpp   | 2 +-
 libstdc++-v3/include/parallel/multiway_merge.h | 4 ++--
 7 files changed, 9 insertions(+), 13 deletions(-)

-- 
2.25.0



[PATCH 3/5] Use func_checker::hash_operand for hashing of GIMPLE operands.

2019-11-13 Thread Martin Liska

gcc/ChangeLog:

2019-11-11  Martin Liska  

* ipa-icf-gimple.h (func_checker::func_checker): Add
default constructor.
* ipa-icf.c (sem_function::init): Make operand_equal_p
and hash_operand public.
(sem_item::add_expr): Remove.
(sem_item::add_type): Remove.
(sem_function::hash_stmt): Use m_checker for hashing
of GIMPLE statements.
(sem_function::parse): Init with checker.
(sem_variable::parse): Pass NULL as checker.
(sem_item_optimizer::parse_funcs_and_vars):
Pass checker to ::parse function.
(sem_item_optimizer::parse_nonsingleton_classes): Likewise.
(sem_variable::parse): New function.
(sem_variable::get_hash): Only return computed hash value.
(sem_variable::init): Initialize hash of a variable.
* ipa-icf.h: Remove add_expr, add_type and add func_checker
to couple of functions as a new argument.
---
 gcc/ipa-icf-gimple.h |  11 ++
 gcc/ipa-icf.c| 239 ---
 gcc/ipa-icf.h|  20 ++--
 3 files changed, 60 insertions(+), 210 deletions(-)

diff --git a/gcc/ipa-icf-gimple.h b/gcc/ipa-icf-gimple.h
index 8213e4f2f46..b59d05fd605 100644
--- a/gcc/ipa-icf-gimple.h
+++ b/gcc/ipa-icf-gimple.h
@@ -121,6 +121,16 @@ public:
 class func_checker : operand_compare
 {
 public:
+  /* Default constructor.  */
+  func_checker ():
+m_source_func_decl (NULL_TREE), m_target_func_decl (NULL_TREE),
+m_ignored_source_nodes (NULL), m_ignored_target_nodes (NULL),
+m_ignore_labels (false)
+  {
+m_source_ssa_names.create (0);
+m_target_ssa_names.create (0);
+  }
+
   /* Initialize internal structures for a given SOURCE_FUNC_DECL and
  TARGET_FUNC_DECL. Strict polymorphic comparison is processed if
  an option COMPARE_POLYMORPHIC is true. For special cases, one can
@@ -254,6 +264,7 @@ private:
   /* Flag if ignore labels in comparison.  */
   bool m_ignore_labels;
 
+public:
   /* Return true if two operands are equal.  The flags fields can be used
  to specify OEP flags described above.  */
   virtual bool operand_equal_p (const_tree, const_tree, unsigned int flags);
diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index 53e387403c8..8297eec9388 100644
--- a/gcc/ipa-icf.c
+++ b/gcc/ipa-icf.c
@@ -1335,8 +1335,9 @@ sem_function::merge (sem_item *alias_item)
 /* Semantic item initialization function.  */
 
 void
-sem_function::init (void)
+sem_function::init (ipa_icf_gimple::func_checker *checker)
 {
+  m_checker = checker;
   if (in_lto_p)
 get_node ()->get_untransformed_body ();
 
@@ -1411,161 +1412,6 @@ sem_function::init (void)
 }
 }
 
-/* Accumulate to HSTATE a hash of expression EXP.
-   Identical to inchash::add_expr, but guaranteed to be stable across LTO
-   and DECL equality classes.  */
-
-void
-sem_item::add_expr (const_tree exp, inchash::hash )
-{
-  if (exp == NULL_TREE)
-{
-  hstate.merge_hash (0);
-  return;
-}
-
-  /* Handled component can be matched in a cureful way proving equivalence
- even if they syntactically differ.  Just skip them.  */
-  STRIP_NOPS (exp);
-  while (handled_component_p (exp))
-exp = TREE_OPERAND (exp, 0);
-
-  enum tree_code code = TREE_CODE (exp);
-  hstate.add_int (code);
-
-  switch (code)
-{
-/* Use inchash::add_expr for everything that is LTO stable.  */
-case VOID_CST:
-case INTEGER_CST:
-case REAL_CST:
-case FIXED_CST:
-case STRING_CST:
-case COMPLEX_CST:
-case VECTOR_CST:
-  inchash::add_expr (exp, hstate);
-  break;
-case CONSTRUCTOR:
-  {
-	unsigned HOST_WIDE_INT idx;
-	tree value;
-
-	hstate.add_hwi (int_size_in_bytes (TREE_TYPE (exp)));
-
-	FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
-	  if (value)
-	add_expr (value, hstate);
-	break;
-  }
-case ADDR_EXPR:
-case FDESC_EXPR:
-  add_expr (get_base_address (TREE_OPERAND (exp, 0)), hstate);
-  break;
-case SSA_NAME:
-case VAR_DECL:
-case CONST_DECL:
-case PARM_DECL:
-  hstate.add_hwi (int_size_in_bytes (TREE_TYPE (exp)));
-  break;
-case MEM_REF:
-case POINTER_PLUS_EXPR:
-case MINUS_EXPR:
-case RANGE_EXPR:
-  add_expr (TREE_OPERAND (exp, 0), hstate);
-  add_expr (TREE_OPERAND (exp, 1), hstate);
-  break;
-case PLUS_EXPR:
-  {
-	inchash::hash one, two;
-	add_expr (TREE_OPERAND (exp, 0), one);
-	add_expr (TREE_OPERAND (exp, 1), two);
-	hstate.add_commutative (one, two);
-  }
-  break;
-CASE_CONVERT:
-  hstate.add_hwi (int_size_in_bytes (TREE_TYPE (exp)));
-  return add_expr (TREE_OPERAND (exp, 0), hstate);
-default:
-  break;
-}
-}
-
-/* Accumulate to HSTATE a hash of type t.
-   TYpes that may end up being compatible after LTO type merging needs to have
-   the same hash.  */
-
-void
-sem_item::add_type (const_tree type, inchash::hash )
-{
-  if (type == NULL_TREE)
-{
-  hstate.merge_hash

[PATCH 5/5] Update statistics about needed symbols in IPA ICF.

2019-11-13 Thread Martin Liska

gcc/ChangeLog:

2019-11-11  Martin Liska  

* ipa-icf.c (sem_item_optimizer::execute): Save
loaded_symbols.
(sem_item_optimizer::parse_nonsingleton_classes):
Return number of loaded symbols.
(sem_item_optimizer::merge_classes): Print
statistics about totally needed symbols.
* ipa-icf.h (parse_nonsingleton_classes): Change return
type.
(merge_classes): Add one argument.
---
 gcc/ipa-icf.c | 20 +---
 gcc/ipa-icf.h |  8 +---
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index 8297eec9388..15aac1cdbe6 100644
--- a/gcc/ipa-icf.c
+++ b/gcc/ipa-icf.c
@@ -2400,7 +2400,7 @@ sem_item_optimizer::execute (void)
 
   dump_cong_classes ();
 
-  parse_nonsingleton_classes ();
+  unsigned int loaded_symbols = parse_nonsingleton_classes ();
   subdivide_classes_by_equality ();
 
   if (dump_file)
@@ -2413,7 +2413,7 @@ sem_item_optimizer::execute (void)
   process_cong_reduction ();
   dump_cong_classes ();
   checking_verify_classes ();
-  bool merged_p = merge_classes (prev_class_count);
+  bool merged_p = merge_classes (prev_class_count, loaded_symbols);
 
   if (dump_file && (dump_flags & TDF_DETAILS))
 symtab->dump (dump_file);
@@ -2587,7 +2587,7 @@ sem_item_optimizer::build_graph (void)
 /* Semantic items in classes having more than one element and initialized.
In case of WPA, we load function body.  */
 
-void
+unsigned int
 sem_item_optimizer::parse_nonsingleton_classes (void)
 {
   unsigned int counter = 0;
@@ -2607,6 +2607,8 @@ sem_item_optimizer::parse_nonsingleton_classes (void)
   float f = m_items.length () ? 100.0f * counter / m_items.length () : 0.0f;
   fprintf (dump_file, "Init called for %u items (%.2f%%).\n", counter, f);
 }
+
+  return counter;
 }
 
 /* Equality function for semantic items is used to subdivide existing
@@ -3214,10 +3216,12 @@ sort_congruence_class_groups_by_decl_uid (const void *a, const void *b)
 /* After reduction is done, we can declare all items in a group
to be equal. PREV_CLASS_COUNT is start number of classes
before reduction. True is returned if there's a merge operation
-   processed. */
+   processed.  LOADED_SYMBOLS is number of symbols that were loaded
+   in WPA.  */
 
 bool
-sem_item_optimizer::merge_classes (unsigned int prev_class_count)
+sem_item_optimizer::merge_classes (unsigned int prev_class_count,
+   unsigned int loaded_symbols)
 {
   unsigned int item_count = m_items.length ();
   unsigned int class_count = m_classes_count;
@@ -3280,8 +3284,10 @@ sem_item_optimizer::merge_classes (unsigned int prev_class_count)
 	   non_singular_classes_count : 0.0f,
 	   non_singular_classes_count);
   fprintf (dump_file, "Equal symbols: %u\n", equal_items);
-  fprintf (dump_file, "Fraction of visited symbols: %.2f%%\n\n",
-	   item_count ? 100.0f * equal_items / item_count : 0.0f);
+  unsigned total = equal_items + non_singular_classes_count;
+  fprintf (dump_file, "Totally needed symbols: %u"
+	   ", fraction of loaded symbols: %.2f%%\n\n", total,
+	   loaded_symbols ? 100.0f * total / loaded_symbols: 0.0f);
 }
 
   unsigned int l;
diff --git a/gcc/ipa-icf.h b/gcc/ipa-icf.h
index 906002214d5..3098fd1f0ce 100644
--- a/gcc/ipa-icf.h
+++ b/gcc/ipa-icf.h
@@ -546,7 +546,7 @@ private:
 
   /* Semantic items in classes having more than one element and initialized.
  In case of WPA, we load function body.  */
-  void parse_nonsingleton_classes (void);
+  unsigned int parse_nonsingleton_classes (void);
 
   /* Equality function for semantic items is used to subdivide existing
  classes. If IN_WPA, fast equality function is invoked.  */
@@ -571,8 +571,10 @@ private:
   /* After reduction is done, we can declare all items in a group
  to be equal. PREV_CLASS_COUNT is start number of classes
  before reduction. True is returned if there's a merge operation
- processed.  */
-  bool merge_classes (unsigned int prev_class_count);
+ processed.  LOADED_SYMBOLS is number of symbols that were loaded
+ in WPA.  */
+  bool merge_classes (unsigned int prev_class_count,
+		  unsigned int loaded_symbols);
 
   /* Fixup points to analysis info.  */
   void fixup_points_to_sets (void);


[PATCH 2/5] Update dump message in IPA ICF.

2019-11-13 Thread Martin Liska

gcc/ChangeLog:

2019-11-11  Martin Liska  

* ipa-icf-gimple.c (func_checker::compare_gimple_call): Update
bail out reason.
(func_checker::compare_gimple_assign): Likewise.
---
 gcc/ipa-icf-gimple.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c
index 7e4ffc852a8..edb8fd66e08 100644
--- a/gcc/ipa-icf-gimple.c
+++ b/gcc/ipa-icf-gimple.c
@@ -579,7 +579,7 @@ func_checker::compare_gimple_call (gcall *s1, gcall *s2)
   t2 = gimple_call_arg (s2, i);
 
   if (!compare_operand (t1, t2))
-	return return_false_with_msg ("memory operands are different");
+	return return_false_with_msg ("GIMPLE call operands are different");
 }
 
   /* Return value checking.  */
@@ -618,7 +618,8 @@ func_checker::compare_gimple_assign (gimple *s1, gimple *s2)
   arg2 = gimple_op (s2, i);
 
   if (!compare_operand (arg1, arg2))
-	return return_false_with_msg ("memory operands are different");
+	return return_false_with_msg ("GIMPLE assignment operands "
+  "are different");
 }
 
 


[PATCH 0/5] IPA ICF: more clean up

2019-11-13 Thread Martin Liska
Hi.

There's another series that brings yet another bunch of clean up
patches:

1) push/pop_cfun is overused, it is not needed
2) make dump reason more precise
3) Do not use custom hashing (add_expr, add_type) and use proper
   func_checker::hash_operand that can be improved for the future.
4) hash FIELD_DECL offset information to improve hashing
5) update statistics about really needed symbols during merging 

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

Martin Liska (5):
  Do not overuse push/pop_cfun in IPA ICF.
  Update dump message in IPA ICF.
  Use func_checker::hash_operand for hashing of GIMPLE operands.
  Handle FIELD_DECL in IPA ICF.
  Update statistics about needed symbols in IPA ICF.

 gcc/ipa-icf-gimple.c |  10 +-
 gcc/ipa-icf-gimple.h |  11 ++
 gcc/ipa-icf.c| 266 +--
 gcc/ipa-icf.h|  28 ++---
 4 files changed, 86 insertions(+), 229 deletions(-)

-- 
2.24.0



[PATCH 1/5] Do not overuse push/pop_cfun in IPA ICF.

2019-11-13 Thread Martin Liska

gcc/ChangeLog:

2019-11-11  Martin Liska  

* ipa-icf.c (sem_function::equals_private): Do not overuse
push/pop_cfun functions.
---
 gcc/ipa-icf.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index 10aa4b76463..53e387403c8 100644
--- a/gcc/ipa-icf.c
+++ b/gcc/ipa-icf.c
@@ -877,14 +877,9 @@ sem_function::equals_private (sem_item *item)
 }
 
   /* Checking all basic blocks.  */
-  push_cfun (DECL_STRUCT_FUNCTION (decl));
   for (unsigned i = 0; i < bb_sorted.length (); ++i)
 if(!m_checker->compare_bb (bb_sorted[i], m_compared_func->bb_sorted[i]))
-  {
-	pop_cfun ();
-	return return_false ();
-  }
-  pop_cfun ();
+  return return_false ();
 
   auto_vec  bb_dict;
 


[PATCH 4/5] Handle FIELD_DECL in IPA ICF.

2019-11-13 Thread Martin Liska

gcc/ChangeLog:

2019-11-11  Martin Liska  

* ipa-icf-gimple.c (func_checker::hash_operand): Improve
func_checker::hash_operand by handling of FIELD_DECLs.
---
 gcc/ipa-icf-gimple.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c
index edb8fd66e08..ac53a1dfbbf 100644
--- a/gcc/ipa-icf-gimple.c
+++ b/gcc/ipa-icf-gimple.c
@@ -234,7 +234,10 @@ func_checker::hash_operand (const_tree arg, inchash::hash ,
 case CONST_DECL:
 case SSA_NAME:
   return;
-
+case FIELD_DECL:
+  inchash::add_expr (DECL_FIELD_OFFSET (arg), hstate, flags);
+  inchash::add_expr (DECL_FIELD_BIT_OFFSET (arg), hstate, flags);
+  return;
 default:
   break;
 }


[PATCH 1/3] Remove leftover call to finalize_options_struct.

2019-11-13 Thread Martin Liska

gcc/ChangeLog:

2019-11-12  Martin Liska  

* tree-streamer-in.c (lto_input_ts_function_decl_tree_pointers):
Remove call to finalize_options_struct.
---
 gcc/tree-streamer-in.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/tree-streamer-in.c b/gcc/tree-streamer-in.c
index d971a74f2b0..b15acb06650 100644
--- a/gcc/tree-streamer-in.c
+++ b/gcc/tree-streamer-in.c
@@ -798,7 +798,6 @@ lto_input_ts_function_decl_tree_pointers (class lto_input_block *ib,
 	cl_optimization_restore (, TREE_OPTIMIZATION (opts));
 	finish_options (, _options_set, UNKNOWN_LOCATION);
 	opts = build_optimization_node ();
-	finalize_options_struct ();
 	DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr) = opts;
   }
   }


[PATCH 2/3] Fix params.exp by parsing output of --help=params -Q.

2019-11-13 Thread Martin Liska

gcc/testsuite/ChangeLog:

2019-11-12  Martin Liska  

* gcc.dg/params/params.exp: Restore test by parsing output
of --help=params -Q.
---
 gcc/testsuite/gcc.dg/params/params.exp | 42 --
 1 file changed, 19 insertions(+), 23 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/params/params.exp b/gcc/testsuite/gcc.dg/params/params.exp
index 801a1e4bc52..191965b82ca 100644
--- a/gcc/testsuite/gcc.dg/params/params.exp
+++ b/gcc/testsuite/gcc.dg/params/params.exp
@@ -31,37 +31,33 @@ proc param_run_test { param_name param_value } {
 dg-runtest $srcdir/$subdir/blocksort-part.c "-O3 --param $param_name=$param_value" ""
 }
 
-set options_file "$objdir/../../params.options"
-if { [info exists TESTING_IN_BUILD_TREE] == 0 } {
-  return
-}
-
-set fd [open $options_file r]
-set text [read $fd]
+set srcfname params-[pid].c
+set fd [open $srcfname w]
+puts $fd ""
 close $fd
+remote_download host $srcfname
+
+set gcc_options "\{additional_flags=--help=params\}"
+set text [gcc_target_compile $srcfname $srcfname.x executable $gcc_options]
+remote_file build delete $srcfname $srcfname.x
 
 # Main loop.
 foreach params [split $text "\n"] {
-set parts [split $params "="]
-set name [string trim [lindex $parts 0] '"']
-set values [split [lindex $parts 1] ","]
-if { [llength $values] == 3 } {
-	set default [lindex $values 0]
-	set min [lindex $values 1]
-	set max [lindex $values 2]
-	set int_max "INT_MAX"
+set parts [split $params " =<>,"]
+if { [llength $parts] >= 8 } {
+  set param [lindex $parts 2]
+  set name [lindex $parts 3]
+  set min [lindex $parts 5]
+  set max [lindex $parts 6]
 
+  if { [ string equal $param "--param" ] && [string is integer -strict $min] && [string is integer -strict $max] } {
 	if { $min != -1 } {
-	param_run_test $name $min
+	  param_run_test $name $min
 	}
-	if { $max != $min && $max > 0 && $max != $int_max } {
-	param_run_test $name $max
-	}
-}
-if { [llength $values] == 5 } {
-	foreach v $values {
-	param_run_test $name $v
+	if { $max != $min && $max > 0 } {
+	  param_run_test $name $max
 	}
+  }
 }
 }
 


[PATCH 0/3] Param conversion fallout

2019-11-13 Thread Martin Liska
Hi.

The patch is about fixing some leftover from the conversion
of parameters to option machinery.

First patch removes a dead call in a OFFLOADING compiler
conditional build. Second fixes params.exp tests and last
is a small update of a comment in opts.c.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

I'm going to install the whole series if there are no objections.
Thanks,
Martin

Martin Liska (3):
  Remove leftover call to finalize_options_struct.
  Fix params.exp by parsing output of --help=params -Q.
  Update comment in opts.c.

 gcc/opts.c |  2 +-
 gcc/testsuite/gcc.dg/params/params.exp | 42 --
 gcc/tree-streamer-in.c |  1 -
 3 files changed, 20 insertions(+), 25 deletions(-)

-- 
2.24.0



[PATCH 3/3] Update comment in opts.c.

2019-11-13 Thread Martin Liska

gcc/ChangeLog:

2019-11-13  Martin Liska  

* opts.c: Update comment about OPT_LEVELS_2_PLUS_SPEED_ONLY.
---
 gcc/opts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/opts.c b/gcc/opts.c
index faf2eef082e..74f05f1b58d 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -508,7 +508,7 @@ static const struct default_options default_options_table[] =
 { OPT_LEVELS_2_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_CHEAP },
 { OPT_LEVELS_2_PLUS, OPT_finline_functions, NULL, 1 },
 
-/* -O2 and -Os optimizations.  */
+/* -O2 and above optimizations, but not -Os or -Og.  */
 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_functions, NULL, 1 },
 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_jumps, NULL, 1 },
 { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_labels, NULL, 1 },


[PATCH 7/7] Fix test-suite fallout.

2019-11-07 Thread Martin Liska

gcc/testsuite/ChangeLog:

2019-11-06  Martin Liska  

* gcc.dg/completion-3.c: Append = to all expected
results and sort expected output.
* gcc.dg/pr83620.c: Update error message.
* gcc.dg/spellcheck-params-2.c: Likewise.
* gcc.dg/spellcheck-params.c: Likewise.
* gcc.misc-tests/help.exp: Update expected output.
---
 gcc/testsuite/gcc.dg/completion-3.c| 16 
 gcc/testsuite/gcc.dg/pr83620.c |  2 +-
 gcc/testsuite/gcc.dg/spellcheck-params-2.c |  2 +-
 gcc/testsuite/gcc.dg/spellcheck-params.c   |  2 +-
 gcc/testsuite/gcc.misc-tests/help.exp  |  4 +---
 5 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/completion-3.c b/gcc/testsuite/gcc.dg/completion-3.c
index 3c4a89ffdd5..a240993dd45 100644
--- a/gcc/testsuite/gcc.dg/completion-3.c
+++ b/gcc/testsuite/gcc.dg/completion-3.c
@@ -2,12 +2,12 @@
 /* { dg-options "--completion=--param=asan-" } */
 
 /* { dg-begin-multiline-output "" }
---param=asan-stack
---param=asan-instrument-allocas
---param=asan-globals
---param=asan-instrument-writes
---param=asan-instrument-reads
---param=asan-memintrin
---param=asan-use-after-return
---param=asan-instrumentation-with-call-threshold
+--param=asan-globals=
+--param=asan-instrument-allocas=
+--param=asan-instrument-reads=
+--param=asan-instrument-writes=
+--param=asan-instrumentation-with-call-threshold=
+--param=asan-memintrin=
+--param=asan-stack=
+--param=asan-use-after-return=
{ dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/gcc.dg/pr83620.c b/gcc/testsuite/gcc.dg/pr83620.c
index e0e44a3b421..cf6eb91197f 100644
--- a/gcc/testsuite/gcc.dg/pr83620.c
+++ b/gcc/testsuite/gcc.dg/pr83620.c
@@ -1,7 +1,7 @@
 /* PR rtl-optimization/86620 */
 /* { dg-do compile } */
 /* { dg-options "-O2 -flive-range-shrinkage --param=max-sched-ready-insns=0" } */
-/* { dg-error "minimum value of parameter 'max-sched-ready-insns' is 1" "" { target *-*-* } 0 } */
+/* { dg-error "argument to '--param=max-sched-ready-insns=' is not between 1 and 65536" "" { target *-*-* } 0 } */
 
 void
 foo (void)
diff --git a/gcc/testsuite/gcc.dg/spellcheck-params-2.c b/gcc/testsuite/gcc.dg/spellcheck-params-2.c
index 8187de43481..0f56241f48f 100644
--- a/gcc/testsuite/gcc.dg/spellcheck-params-2.c
+++ b/gcc/testsuite/gcc.dg/spellcheck-params-2.c
@@ -1,4 +1,4 @@
 /* { dg-do compile } */
 /* { dg-options "--param does-not-resemble-anything=42" } */
-/* { dg-error "invalid '--param' name 'does-not-resemble-anything'"  "" { target *-*-* } 0 } */
+/* { dg-error "unrecognized command-line option '--param=does-not-resemble-anything=42'"  "" { target *-*-* } 0 } */
 
diff --git a/gcc/testsuite/gcc.dg/spellcheck-params.c b/gcc/testsuite/gcc.dg/spellcheck-params.c
index 01e1343ab9e..4010a5df0d2 100644
--- a/gcc/testsuite/gcc.dg/spellcheck-params.c
+++ b/gcc/testsuite/gcc.dg/spellcheck-params.c
@@ -1,4 +1,4 @@
 /* { dg-do compile } */
 /* { dg-options "--param max-early-inliner-iteration=3" } */
-/* { dg-error "invalid '--param' name 'max-early-inliner-iteration'; did you mean 'max-early-inliner-iterations'?"  "" { target *-*-* } 0 } */
+/* { dg-error "unrecognized command-line option '--param=max-early-inliner-iteration=3'; did you mean '--param=max-early-inliner-iterations='?"  "" { target *-*-* } 0 } */
 
diff --git a/gcc/testsuite/gcc.misc-tests/help.exp b/gcc/testsuite/gcc.misc-tests/help.exp
index 4bb359f698d..60e794b1f46 100644
--- a/gcc/testsuite/gcc.misc-tests/help.exp
+++ b/gcc/testsuite/gcc.misc-tests/help.exp
@@ -64,7 +64,7 @@ check_for_options c "-v --help" "" {are likely to\n  -std} ""
 check_for_options c "--help=optimizers" "-O" "  -g  " ""
 check_for_options c "--help=params" "maximum number of" "-Wunsafe-loop-optimizations" ""
 check_for_options_with_filter c "--help=params" \
-"^The --param option recognizes the following as parameters:$" "" {[^.]$} ""
+"^The following options control parameters:$" "" {[^.]$} ""
 check_for_options c "--help=C" "-ansi" "-gnatO" ""
 check_for_options c {--help=C++} {-std=c\+\+} "-gnatO" ""
 check_for_options c "--help=common" "-dumpbase" "-gnatO" ""
@@ -133,8 +133,6 @@ check_for_options c "--help=warnings,^joined" \
 "^ +-Wtrigraphs" "^ +-Wformat=" ""
 check_for_options c "--help=joined,separate" \
 "^ +-I" "" ""
-check_for_options c "--help=^joined,separate" \
-"^ +--param " "" ""
 check_for_options c "--help=joined,^separate" \
 "^ +--help=" "" ""
 check_for_options c "--help=joined,undocumented" "" "" ""


[PATCH 5/7] Remove last leftover usage of params* files.

2019-11-07 Thread Martin Liska

gcc/ChangeLog:

2019-11-06  Martin Liska  

* common.opt: Remove param_values.
* config/i386/i386-options.c (ix86_valid_target_attribute_p):
Remove finalize_options_struct.
* gcc.c (driver::decode_argv): Do not call global_init_params
and finish_params.
(driver::finalize): Do not call params_c_finalize
and finalize_options_struct.
* opt-suggestions.c (option_proposer::get_completions): Remove
special casing of params.
(option_proposer::find_param_completions): Remove.
(test_completion_partial_match): Update expected output.
* opt-suggestions.h: Remove find_param_completions.
* opts-common.c (add_misspelling_candidates): Add
--param with a space.
* opts.c (handle_param): Remove.
(init_options_struct):. Remove init_options_struct and
similar calls.
(finalize_options_struct): Remove.
(common_handle_option): Use SET_OPTION_IF_UNSET.
* opts.h (finalize_options_struct): Remove.
* toplev.c (general_init): Do not call global_init_params.
(toplev::finalize): Do not call params_c_finalize and
finalize_options_struct.
---
 gcc/common.opt |  3 --
 gcc/config/i386/i386-options.c |  2 -
 gcc/gcc.c  |  8 
 gcc/opt-suggestions.c  | 58 ++-
 gcc/opt-suggestions.h  |  5 ---
 gcc/opts-common.c  | 11 ++
 gcc/opts.c | 71 ++
 gcc/opts.h |  1 -
 gcc/toplev.c   |  8 
 9 files changed, 27 insertions(+), 140 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 8c6acabb1fc..26b6c2ce9e1 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -63,9 +63,6 @@ int flag_complex_method = 1
 Variable
 bool flag_warn_unused_result = false
 
-Variable
-int *param_values
-
 ; Nonzero if we should write GIMPLE bytecode for link-time optimization.
 Variable
 int flag_generate_lto
diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
index 1e3280d1bb9..c909f8ea1ed 100644
--- a/gcc/config/i386/i386-options.c
+++ b/gcc/config/i386/i386-options.c
@@ -1340,8 +1340,6 @@ ix86_valid_target_attribute_p (tree fndecl,
 	DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
 }
 
-  finalize_options_struct (_options);
-
   return ret;
 }
 
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 159ffe7cb53..539ded01ce6 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -7422,10 +7422,6 @@ driver::expand_at_files (int *argc, char ***argv) const
 void
 driver::decode_argv (int argc, const char **argv)
 {
-  /* Register the language-independent parameters.  */
-  global_init_params ();
-  finish_params ();
-
   init_opts_obstack ();
   init_options_struct (_options, _options_set);
 
@@ -10113,7 +10109,6 @@ void
 driver::finalize ()
 {
   env.restore ();
-  params_c_finalize ();
   diagnostic_finish (global_dc);
 
   is_cpp_driver = 0;
@@ -10134,9 +10129,6 @@ driver::finalize ()
   spec_machine = DEFAULT_TARGET_MACHINE;
   greatest_status = 1;
 
-  finalize_options_struct (_options);
-  finalize_options_struct (_options_set);
-
   obstack_free (, NULL);
   obstack_free (_obstack, NULL); /* in opts.c */
   obstack_free (_obstack, NULL);
diff --git a/gcc/opt-suggestions.c b/gcc/opt-suggestions.c
index 609e60bd20a..01ce331eb0e 100644
--- a/gcc/opt-suggestions.c
+++ b/gcc/opt-suggestions.c
@@ -64,32 +64,17 @@ option_proposer::get_completions (const char *option_prefix,
 
   size_t length = strlen (option_prefix);
 
-  /* Handle OPTION_PREFIX starting with "-param".  */
-  const char *prefix = "-param";
-  if (length >= strlen (prefix)
-  && strstr (option_prefix, prefix) == option_prefix)
-{
-  /* We support both '-param-xyz=123' and '-param xyz=123' */
-  option_prefix += strlen (prefix);
-  char separator = option_prefix[0];
-  option_prefix++;
-  if (separator == ' ' || separator == '=')
-	find_param_completions (separator, option_prefix, results);
-}
-  else
-{
-  /* Lazily populate m_option_suggestions.  */
-  if (!m_option_suggestions)
-	build_option_suggestions (option_prefix);
-  gcc_assert (m_option_suggestions);
+  /* Lazily populate m_option_suggestions.  */
+  if (!m_option_suggestions)
+build_option_suggestions (option_prefix);
+  gcc_assert (m_option_suggestions);
 
-  for (unsigned i = 0; i < m_option_suggestions->length (); i++)
-	{
-	  char *candidate = (*m_option_suggestions)[i];
-	  if (strlen (candidate) >= length
-	  && strstr (candidate, option_prefix) == candidate)
-	results.safe_push (concat ("-", candidate, NULL));
-	}
+  for (unsigned i = 0; i < m_option_suggestions->length (); i++)
+{
+  char *candidate = (*m_option_suggestions)[i];
+  if (strlen (candidate) >= length
+	  && strstr (candidate, opt

[PATCH 6/7] Remove set_default_param_value from documentation.

2019-11-07 Thread Martin Liska

gcc/ChangeLog:

2019-11-06  Martin Liska  

* common/common-target.def:
Do not mention set_default_param_value
and set_param_value.
* doc/tm.texi: Likewise.
---
 gcc/common/common-target.def | 6 ++
 gcc/doc/tm.texi  | 4 ++--
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/gcc/common/common-target.def b/gcc/common/common-target.def
index 41b7e704c2e..48096720e44 100644
--- a/gcc/common/common-target.def
+++ b/gcc/common/common-target.def
@@ -51,15 +51,13 @@ DEFHOOKPOD
 
 DEFHOOK
 (option_default_params,
-"Set target-dependent default values for @option{--param} settings, using\
- calls to @code{set_default_param_value}.",
+"Set target-dependent default values for @option{--param} settings.",
  void, (void),
  hook_void_void)
 
 DEFHOOK
 (option_validate_param,
-"Validate target-dependent value for @option{--param} settings, using\
- calls to @code{set_param_value}.",
+"Validate target-dependent value for @option{--param} settings.",
  bool, (int, int),
  default_option_validate_param)
 
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index cd9aed9874f..f6bc31bef65 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -759,11 +759,11 @@ Set target-dependent initial values of fields in @var{opts}.
 @end deftypefn
 
 @deftypefn {Common Target Hook} void TARGET_OPTION_DEFAULT_PARAMS (void)
-Set target-dependent default values for @option{--param} settings, using calls to @code{set_default_param_value}.
+Set target-dependent default values for @option{--param} settings.
 @end deftypefn
 
 @deftypefn {Common Target Hook} bool TARGET_OPTION_VALIDATE_PARAM (int, @var{int})
-Validate target-dependent value for @option{--param} settings, using calls to @code{set_param_value}.
+Validate target-dependent value for @option{--param} settings.
 @end deftypefn
 
 @defmac SWITCHABLE_TARGET


[PATCH 2/7] Include new generated gcc/params.opt file.

2019-11-07 Thread Martin Liska

gcc/ChangeLog:

2019-11-06  Martin Liska  

* Makefile.in: Include params.opt.
* flag-types.h (enum parloops_schedule_type): Add
parloops_schedule_type used in params.opt.
* params.opt: New file.
---
 gcc/Makefile.in  |   2 +-
 gcc/flag-types.h |  11 +
 gcc/params.opt   | 967 +++
 3 files changed, 979 insertions(+), 1 deletion(-)
 create mode 100644 gcc/params.opt

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 95f054c4d4f..ed47a346689 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -567,7 +567,7 @@ xm_include_list=@xm_include_list@
 xm_defines=@xm_defines@
 lang_checks=
 lang_checks_parallelized=
-lang_opt_files=@lang_opt_files@ $(srcdir)/c-family/c.opt $(srcdir)/common.opt
+lang_opt_files=@lang_opt_files@ $(srcdir)/c-family/c.opt $(srcdir)/common.opt $(srcdir)/params.opt
 lang_specs_files=@lang_specs_files@
 lang_tree_files=@lang_tree_files@
 target_cpu_default=@target_cpu_default@
diff --git a/gcc/flag-types.h b/gcc/flag-types.h
index b23d3a271f1..0c23aadefed 100644
--- a/gcc/flag-types.h
+++ b/gcc/flag-types.h
@@ -370,4 +370,15 @@ enum cf_protection_level
   CF_FULL = CF_BRANCH | CF_RETURN,
   CF_SET = 1 << 2
 };
+
+/* Parloops schedule type.  */
+enum parloops_schedule_type
+{
+  PARLOOPS_SCHEDULE_STATIC = 0,
+  PARLOOPS_SCHEDULE_DYNAMIC,
+  PARLOOPS_SCHEDULE_GUIDED,
+  PARLOOPS_SCHEDULE_AUTO,
+  PARLOOPS_SCHEDULE_RUNTIME
+};
+
 #endif /* ! GCC_FLAG_TYPES_H */
diff --git a/gcc/params.opt b/gcc/params.opt
new file mode 100644
index 000..7f2f8610c40
--- /dev/null
+++ b/gcc/params.opt
@@ -0,0 +1,967 @@
+; Parameter options of the compiler.
+
+; Copyright (C) 2019 Free Software Foundation, Inc.
+;
+; This file is part of GCC.
+;
+; GCC is free software; you can redistribute it and/or modify it under
+; the terms of the GNU General Public License as published by the Free
+; Software Foundation; either version 3, or (at your option) any later
+; version.
+;
+; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+; WARRANTY; without even the implied warranty of MERCHANTABILITY or
+; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+; for more details.
+;
+; You should have received a copy of the GNU General Public License
+; along with GCC; see the file COPYING3.  If not see
+; <http://www.gnu.org/licenses/>.
+
+; See the GCC internals manual (options.texi) for a description of this file's format.
+
+; Please try to keep this file in ASCII collating order.
+
+-param=align-loop-iterations=
+Common Joined UInteger Var(param_align_loop_iterations) Optimization Init(4) Param
+Loops iterating at least selected number of iterations will get loop alignment.
+
+-param=align-threshold=
+Common Joined UInteger Var(param_align_threshold) Optimization Init(100) IntegerRange(1, 65536) Param
+Select fraction of the maximal frequency of executions of basic block in function given basic block get alignment.
+
+-param=asan-globals=
+Common Joined UInteger Var(param_asan_globals) Init(1) IntegerRange(0, 1) Param
+Enable asan globals protection.
+
+-param=asan-instrument-allocas=
+Common Joined UInteger Var(param_asan_protect_allocas) Init(1) IntegerRange(0, 1) Param
+Enable asan allocas/VLAs protection.
+
+-param=asan-instrument-reads=
+Common Joined UInteger Var(param_asan_instrument_reads) Init(1) IntegerRange(0, 1) Param
+Enable asan load operations protection.
+
+-param=asan-instrument-writes=
+Common Joined UInteger Var(param_asan_instrument_writes) Init(1) IntegerRange(0, 1) Param
+Enable asan store operations protection.
+
+-param=asan-instrumentation-with-call-threshold=
+Common Joined UInteger Var(param_asan_instrumentation_with_call_threshold) Optimization Init(7000) Param
+Use callbacks instead of inline code if number of accesses in function becomes greater or equal to this number.
+
+-param=asan-memintrin=
+Common Joined UInteger Var(param_asan_memintrin) Init(1) IntegerRange(0, 1) Param
+Enable asan builtin functions protection.
+
+-param=asan-stack=
+Common Joined UInteger Var(param_asan_stack) Init(1) IntegerRange(0, 1) Param
+Enable asan stack protection.
+
+-param=asan-use-after-return=
+Common Joined UInteger Var(param_asan_use_after_return) Init(1) IntegerRange(0, 1) Param
+Enable asan detection of use-after-return bugs.
+
+-param=avg-loop-niter=
+Common Joined UInteger Var(param_avg_loop_niter) Optimization Init(10) IntegerRange(1, 65536) Param
+Average number of iterations of a loop.
+
+-param=avoid-fma-max-bits=
+Common Joined UInteger Var(param_avoid_fma_max_bits) Optimization IntegerRange(0, 512) Param
+Maximum number of bits for which we avoid creating FMAs.
+
+-param=builtin-expect-probability=
+Common Joined UInteger Var(param_builtin_expect_probability) Optimization Init(90) IntegerRange(0, 100) Param
+Set the estimated probability in percentage for builtin expect. The default value is 90% probability.
+
+-param=builtin-string-cmp-inline-length=
+C

[PATCH 0/7] Param conversion to option machinery

2019-11-07 Thread Martin Liska
The email thread is follow up of a demo that I made here:
https://gcc.gnu.org/ml/gcc-patches/2019-10/msg02220.html

The patchset converts current param infrastructure to
the option machinery. The parts 3 and 4 are quite
mechanical.

I would appreciate a feedback about what parameters
should be per function (Optimization keyword) and global.

The patch survives bootstrap and regtests on x86_64-linux-gnu
and ppc64-linux-gnu and I made cross build of all target compilers.

Thoughts?
Martin

Martin Liska (7):
  Param to options conversion.
  Include new generated gcc/params.opt file.
  Apply mechanical replacement (generated patch).
  Remove gcc/params.* files.
  Remove last leftover usage of params* files.
  Remove set_default_param_value from documentation.
  Fix test-suite fallout.

 gcc/Makefile.in   |   20 +-
 gcc/asan.c|   19 +-
 gcc/auto-profile.c|3 +-
 gcc/bb-reorder.c  |5 +-
 gcc/builtins.c|3 +-
 gcc/c/gimple-parser.c |3 +-
 gcc/cfgcleanup.c  |5 +-
 gcc/cfgexpand.c   |9 +-
 gcc/cfgloopanal.c |9 +-
 gcc/cgraph.c  |3 +-
 gcc/combine.c |5 +-
 gcc/common.opt|   10 -
 gcc/common/common-target.def  |6 +-
 gcc/common/config/aarch64/aarch64-common.c|   16 +-
 gcc/common/config/gcn/gcn-common.c|1 -
 gcc/common/config/ia64/ia64-common.c  |9 +-
 .../config/powerpcspe/powerpcspe-common.c |3 +-
 gcc/common/config/rs6000/rs6000-common.c  |3 +-
 gcc/common/config/sh/sh-common.c  |3 +-
 gcc/config/aarch64/aarch64.c  |   80 +-
 gcc/config/alpha/alpha.c  |   17 +-
 gcc/config/arm/arm.c  |   44 +-
 gcc/config/avr/avr.c  |1 -
 gcc/config/csky/csky.c|1 -
 gcc/config/i386/i386-builtins.c   |1 -
 gcc/config/i386/i386-expand.c |1 -
 gcc/config/i386/i386-features.c   |1 -
 gcc/config/i386/i386-options.c|   35 +-
 gcc/config/i386/i386.c|   27 +-
 gcc/config/ia64/ia64.c|3 +-
 gcc/config/rs6000/rs6000-logue.c  |5 +-
 gcc/config/rs6000/rs6000.c|   56 +-
 gcc/config/s390/s390.c|   80 +-
 gcc/config/sparc/sparc.c  |   84 +-
 gcc/config/visium/visium.c|7 +-
 gcc/coverage.c|9 +-
 gcc/cp/name-lookup.c  |3 +-
 gcc/cp/typeck.c   |5 +-
 gcc/cprop.c   |1 -
 gcc/cse.c |7 +-
 gcc/cselib.c  |3 +-
 gcc/doc/options.texi  |3 +
 gcc/doc/tm.texi   |4 +-
 gcc/dse.c |3 +-
 gcc/emit-rtl.c|   19 +-
 gcc/explow.c  |3 +-
 gcc/final.c   |5 +-
 gcc/flag-types.h  |   11 +
 gcc/fold-const.c  |   13 +-
 gcc/gcc.c |9 -
 gcc/gcse.c|   17 +-
 gcc/ggc-common.c  |5 +-
 gcc/ggc-page.c|5 +-
 gcc/gimple-loop-interchange.cc|7 +-
 gcc/gimple-loop-jam.c |9 +-
 gcc/gimple-loop-versioning.cc |5 +-
 gcc/gimple-ssa-split-paths.c  |3 +-
 gcc/gimple-ssa-sprintf.c  |1 -
 gcc/gimple-ssa-store-merging.c|9 +-
 gcc/gimple-ssa-strength-reduction.c   |3 +-
 gcc/gimple-ssa-warn-alloca.c  |1 -
 gcc/gimple-ssa-warn-restrict.c|1 -
 gcc/graphite-isl-ast-to-gimple.c  |5 +-
 gcc/graphite-optimize-isl.c   |5 +-
 gcc/graphite-scop-detection.c |5 +-
 gcc/graphite-sese-to-poly.c   |1 -
 gcc/graphite.c|1 -
 gcc/haifa-sched.c |   39 +-
 gcc/hsa-gen.c |3 +-
 gcc/ifcvt.c   |5 +-
 gcc/ipa-cp.c  |   31 +-
 gcc/ipa-fnsummary.c   |   21 +-
 gcc/ipa-inline-analysis.c |3 +-
 gcc/ipa-inline.c  |   78

[PATCH 1/7] Param to options conversion.

2019-11-07 Thread Martin Liska

gcc/ChangeLog:

2019-11-06  Martin Liska  

* common.opt: Remove --param and --param= options.
* opt-functions.awk: Mark CL_PARAMS for options
that have Param keyword.
* opts-common.c (decode_cmdline_options_to_array):
Replace --param key=value with --param=key=value.
* opts.c (print_filtered_help): Remove special
printing of params.
(print_specific_help): Update title for params.
(common_handle_option): Do not handle OPT__param.
opts.h (SET_OPTION_IF_UNSET): New macro.
* doc/options.texi: Document Param keyword.
---
 gcc/common.opt|  7 ---
 gcc/doc/options.texi  |  3 +++
 gcc/opt-functions.awk |  3 ++-
 gcc/opts-common.c |  9 +
 gcc/opts.c| 38 +-
 gcc/opts.h| 10 ++
 6 files changed, 25 insertions(+), 45 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 12c0083964e..8c6acabb1fc 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -437,13 +437,6 @@ Common Driver Alias(-target-help)
 fversion
 Common Driver Alias(-version)
 
--param
-Common Separate
---param =	Set parameter  to value.  See below for a complete list of parameters.
-
--param=
-Common Joined Alias(-param)
-
 -sysroot
 Driver Separate Alias(-sysroot=)
 
diff --git a/gcc/doc/options.texi b/gcc/doc/options.texi
index b59f4d39aef..c7c70acd526 100644
--- a/gcc/doc/options.texi
+++ b/gcc/doc/options.texi
@@ -475,6 +475,9 @@ affect executable code generation may use this flag instead, so that the
 option is not taken into account in ways that might affect executable
 code generation.
 
+@item Param
+This is an option that is a parameter.
+
 @item Undocumented
 The option is deliberately missing documentation and should not
 be included in the @option{--help} output.
diff --git a/gcc/opt-functions.awk b/gcc/opt-functions.awk
index c1da80c648c..4f02b74e97c 100644
--- a/gcc/opt-functions.awk
+++ b/gcc/opt-functions.awk
@@ -105,7 +105,8 @@ function switch_flags (flags)
 	  test_flag("Undocumented", flags,  " | CL_UNDOCUMENTED") \
 	  test_flag("NoDWARFRecord", flags,  " | CL_NO_DWARF_RECORD") \
 	  test_flag("Warning", flags,  " | CL_WARNING") \
-	  test_flag("(Optimization|PerFunction)", flags,  " | CL_OPTIMIZATION")
+	  test_flag("(Optimization|PerFunction)", flags,  " | CL_OPTIMIZATION") \
+	  test_flag("Param", flags,  " | CL_PARAMS")
 	sub( "^0 \\| ", "", result )
 	return result
 }
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index b4ec1bd25ac..d55dc93e165 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -961,6 +961,15 @@ decode_cmdline_options_to_array (unsigned int argc, const char **argv,
 	  continue;
 	}
 
+  /* Interpret "--param" "key=name" as "--param=key=name".  */
+  const char *needle = "--param";
+  if (i + 1 < argc && strcmp (opt, needle) == 0)
+	{
+	  const char *replacement
+	= opts_concat (needle, "=", argv[i + 1], NULL);
+	  argv[++i] = replacement;
+	}
+
   n = decode_cmdline_option (argv + i, lang_mask,
  _array[num_decoded_options]);
   num_decoded_options++;
diff --git a/gcc/opts.c b/gcc/opts.c
index f46b468a968..394cbfd1c56 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -1278,38 +1278,6 @@ print_filtered_help (unsigned int include_flags,
   bool displayed = false;
   char new_help[256];
 
-  if (include_flags == CL_PARAMS)
-{
-  for (i = 0; i < LAST_PARAM; i++)
-	{
-	  const char *param = compiler_params[i].option;
-
-	  help = compiler_params[i].help;
-	  if (help == NULL || *help == '\0')
-	{
-	  if (exclude_flags & CL_UNDOCUMENTED)
-		continue;
-	  help = undocumented_msg;
-	}
-
-	  /* Get the translation.  */
-	  help = _(help);
-
-	  if (!opts->x_quiet_flag)
-	{
-	  snprintf (new_help, sizeof (new_help),
-			_("default %d minimum %d maximum %d"),
-			compiler_params[i].default_value,
-			compiler_params[i].min_value,
-			compiler_params[i].max_value);
-	  help = new_help;
-	}
-	  wrap_help (help, param, strlen (param), columns);
-	}
-  putchar ('\n');
-  return;
-}
-
   if (!opts->x_help_printed)
 opts->x_help_printed = XCNEWVAR (char, cl_options_count);
 
@@ -1679,7 +1647,7 @@ print_specific_help (unsigned int include_flags,
 	  description = _("The following options are language-independent");
 	  break;
 	case CL_PARAMS:
-	  description = _("The --param option recognizes the following as parameters");
+	  description = _("The following options control parameters");
 	  break;
 	default:
 	  if (i >= cl_lang_count)
@@ -2241,10 +2209,6 @@ common_handle_option (struct gcc_options *opts,
 
   switch (code)
 {
-case OPT__param:
-  handle_param (opts, opts_se

[PATCH 3/5] Reapply all revisions mentioned in LOCAL_PATCHES.

2019-11-05 Thread Martin Liska

libsanitizer/ChangeLog:

2019-11-05  Martin Liska  

* asan/asan_globals.cpp (CheckODRViolationViaIndicator): Reapply from
LOCAL_PATCHES.
(CheckODRViolationViaPoisoning): Likewise.
(RegisterGlobal): Likewise.
* asan/asan_interceptors.h 
(ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION): Likewise.
(defined): Likewise.
* asan/asan_mapping.h: Likewise.
* sanitizer_common/sanitizer_linux_libcdep.cpp (defined): Likewise.
* sanitizer_common/sanitizer_mac.cpp (defined): Likewise.
* sanitizer_common/sanitizer_platform_limits_linux.cpp (defined): 
Likewise.
* sanitizer_common/sanitizer_platform_limits_posix.h: Likewise.
* sanitizer_common/sanitizer_stacktrace.cpp (GetCanonicFrame): Likewise.
* tsan/tsan_rtl_ppc64.S: Likewise.
* ubsan/ubsan_handlers.cpp (__ubsan::__ubsan_handle_cfi_bad_icall): 
Likewise.
(__ubsan::__ubsan_handle_cfi_bad_icall_abort): Likewise.
* ubsan/ubsan_handlers.h (struct CFIBadIcallData): Likewise.
(struct CFICheckFailData): Likewise.
(RECOVERABLE): Likewise.
* ubsan/ubsan_platform.h: Likewise.
---
 libsanitizer/asan/asan_globals.cpp| 19 ---
 libsanitizer/asan/asan_interceptors.h |  7 ++-
 libsanitizer/asan/asan_mapping.h  |  2 +-
 .../sanitizer_linux_libcdep.cpp   |  4 
 .../sanitizer_common/sanitizer_mac.cpp|  2 +-
 .../sanitizer_platform_limits_linux.cpp   |  7 +--
 .../sanitizer_platform_limits_posix.h |  2 +-
 .../sanitizer_common/sanitizer_stacktrace.cpp | 17 -
 libsanitizer/tsan/tsan_rtl_ppc64.S|  1 +
 libsanitizer/ubsan/ubsan_handlers.cpp | 15 +++
 libsanitizer/ubsan/ubsan_handlers.h   |  8 
 libsanitizer/ubsan/ubsan_platform.h   |  2 ++
 12 files changed, 56 insertions(+), 30 deletions(-)

diff --git a/libsanitizer/asan/asan_globals.cpp b/libsanitizer/asan/asan_globals.cpp
index 9d7dbc6f264..e045c31cd1c 100644
--- a/libsanitizer/asan/asan_globals.cpp
+++ b/libsanitizer/asan/asan_globals.cpp
@@ -154,23 +154,6 @@ static void CheckODRViolationViaIndicator(const Global *g) {
   }
 }
 
-// Check ODR violation for given global G by checking if it's already poisoned.
-// We use this method in case compiler doesn't use private aliases for global
-// variables.
-static void CheckODRViolationViaPoisoning(const Global *g) {
-  if (__asan_region_is_poisoned(g->beg, g->size_with_redzone)) {
-// This check may not be enough: if the first global is much larger
-// the entire redzone of the second global may be within the first global.
-for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) {
-  if (g->beg == l->g->beg &&
-  (flags()->detect_odr_violation >= 2 || g->size != l->g->size) &&
-  !IsODRViolationSuppressed(g->name))
-ReportODRViolation(g, FindRegistrationSite(g),
-   l->g, FindRegistrationSite(l->g));
-}
-  }
-}
-
 // Clang provides two different ways for global variables protection:
 // it can poison the global itself or its private alias. In former
 // case we may poison same symbol multiple times, that can help us to
@@ -216,8 +199,6 @@ static void RegisterGlobal(const Global *g) {
 // where two globals with the same name are defined in different modules.
 if (UseODRIndicator(g))
   CheckODRViolationViaIndicator(g);
-else
-  CheckODRViolationViaPoisoning(g);
   }
   if (CanPoisonMemory())
 PoisonRedZones(*g);
diff --git a/libsanitizer/asan/asan_interceptors.h b/libsanitizer/asan/asan_interceptors.h
index 344a64bd83d..b7a85fedbdf 100644
--- a/libsanitizer/asan/asan_interceptors.h
+++ b/libsanitizer/asan/asan_interceptors.h
@@ -80,7 +80,12 @@ void InitializePlatformInterceptors();
 #if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \
 !SANITIZER_NETBSD
 # define ASAN_INTERCEPT___CXA_THROW 1
-# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
+# if ! defined(ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION) \
+ || ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION
+#   define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
+# else
+#   define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 0
+# endif
 # if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__))
 #  define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1
 # else
diff --git a/libsanitizer/asan/asan_mapping.h b/libsanitizer/asan/asan_mapping.h
index 41fb49ee46d..09be904270c 100644
--- a/libsanitizer/asan/asan_mapping.h
+++ b/libsanitizer/asan/asan_mapping.h
@@ -163,7 +163,7 @@ static const u64 kDefaultShort64bitShadowOffset =
 static const u64 kAArch64_ShadowOffset64 = 1ULL << 36;
 static const u64 kMIPS32_ShadowOffset32 = 0x0aaa;
 static const u64 kMIPS64_ShadowOffset64 = 1ULL << 37;
-sta

[PATCH 5/5] Update scanned patterns in a test-case.

2019-11-05 Thread Martin Liska

gcc/testsuite/ChangeLog:

2019-11-05  Martin Liska  

* c-c++-common/ubsan/ptr-overflow-2.c: Update based on changed
run-time reporting format.
---
 gcc/testsuite/c-c++-common/ubsan/ptr-overflow-2.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/ubsan/ptr-overflow-2.c b/gcc/testsuite/c-c++-common/ubsan/ptr-overflow-2.c
index a1110a2ddbc..9e72401d792 100644
--- a/gcc/testsuite/c-c++-common/ubsan/ptr-overflow-2.c
+++ b/gcc/testsuite/c-c++-common/ubsan/ptr-overflow-2.c
@@ -93,16 +93,16 @@ main ()
   return 0;
 }
 
-/* { dg-output ":5:6\[79]\[^\n\r]*runtime error: pointer index expression with base (0\[xX])?\[fF]\+ overflowed to (0\[xX])?0\+(\n|\r\n|\r)" } */
-/* { dg-output "\[^\n\r]*:6:6\[79]\[^\n\r]*runtime error: pointer index expression with base (0\[xX])?0\+ overflowed to (0\[xX])?\[fF]\+(\n|\r\n|\r)" } */
-/* { dg-output "\[^\n\r]*:7:7\[46]\[^\n\r]*runtime error: pointer index expression with base (0\[xX])?\[fF]\+9 overflowed to (0\[xX])?0\+(\n|\r\n|\r)" } */
+/* { dg-output ":5:6\[79]\[^\n\r]*runtime error: applying non-zero offset to non-null pointer (0\[xX])?\[fF]\+ produced null pointer(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*:6:6\[79]\[^\n\r]*runtime error: applying non-zero offset \[0-9]\+ to null pointer(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*:7:7\[46]\[^\n\r]*runtime error: applying non-zero offset to non-null pointer (0\[xX])?\[fF]\+9 produced null pointer(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*:8:7\[46]\[^\n\r]*runtime error: pointer index expression with base (0\[xX])?0\+3 overflowed to (0\[xX])?\[fF]\+(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*:9:7\[46]\[^\n\r]*runtime error: pointer index expression with base (0\[xX])?0\+17 overflowed to (0\[xX])?\[fF]\+\[cC](\n|\r\n|\r)" } */
-/* { dg-output "\[^\n\r]*:10:7\[46]\[^\n\r]*runtime error: pointer index expression with base (0\[xX])?\[fF]\+1 overflowed to (0\[xX])?0\+(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*:10:7\[46]\[^\n\r]*runtime error: applying non-zero offset to non-null pointer (0\[xX])?\[fF]\+1 produced null pointer(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*:11:\[89]\[80]\[^\n\r]*runtime error: pointer index expression with base (0\[xX])?\[fF]\+\[eE]3 overflowed to (0\[xX])?0\+2(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*:13:\[89]\[80]\[^\n\r]*runtime error: pointer index expression with base (0\[xX])?0\+17 overflowed to (0\[xX])?\[fF]\+(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*:12:\[89]\[80]\[^\n\r]*runtime error: pointer index expression with base (0\[xX])?0\+7 overflowed to (0\[xX])?\[fF]\+(\n|\r\n|\r)" } */
-/* { dg-output "\[^\n\r]*:14:\[89]\[91]\[^\n\r]*runtime error: pointer index expression with base (0\[xX])?\[fF]\+\[eE]7 overflowed to (0\[xX])?0\+" } */
+/* { dg-output "\[^\n\r]*:14:\[89]\[91]\[^\n\r]*runtime error: applying non-zero offset to non-null pointer (0\[xX])?\[fF]\+\[eE]7 produced null pointer" } */
 /* { dg-output "(\n|\r\n|\r)" { target int32 } } */
 /* { dg-output "\[^\n\r]*:17:\[67]\[82]\[^\n\r]*runtime error: pointer index expression with base (0\[xX])?\[fF]\+ overflowed to (0\[xX])?0\+3(\n|\r\n|\r)" { target int32 } } */
 /* { dg-output "\[^\n\r]*:18:\[67]\[86]\[^\n\r]*runtime error: pointer index expression with base (0\[xX])?\[fF]\+ overflowed to (0\[xX])?0\+107(\n|\r\n|\r)" { target int32 } } */


[PATCH 0/5] libsanitizer: merge from trunk

2019-11-05 Thread Martin Liska
Hi.

I've just done merge from trunk for libsanitizer.

I bootstrapped the patch set on x86_64-linux-gnu and run
asan/ubsan/tsan tests on x86_64, ppc64le (power8) and
aarch64.

Plus I run ubsan and asan boostrap on ppc64le-linux-gnu and
abidiff is fine comparing the current trunk with the merged
libsanitizer.

I'll install the patches if there are no objections.

Martin

Martin Liska (5):
  Libsanitizer: merge from trunk with merge.sh.
  Update Makefile.am.
  Reapply all revisions mentioned in LOCAL_PATCHES.
  Set print_summary for UBSAN.
  Update scanned patterns in a test-case.

 .../c-c++-common/ubsan/ptr-overflow-2.c   |   10 +-
 libsanitizer/BlocksRuntime/Block.h|   59 +
 libsanitizer/BlocksRuntime/Block_private.h|  179 ++
 libsanitizer/MERGE|2 +-
 libsanitizer/asan/asan_allocator.cpp  |2 +-
 libsanitizer/asan/asan_debugging.cpp  |8 +-
 libsanitizer/asan/asan_descriptions.h |2 +-
 libsanitizer/asan/asan_errors.cpp |5 +-
 libsanitizer/asan/asan_errors.h   |3 +-
 libsanitizer/asan/asan_flags.inc  |   13 +-
 libsanitizer/asan/asan_globals.cpp|8 +-
 libsanitizer/asan/asan_globals_win.cpp|8 +-
 libsanitizer/asan/asan_interceptors.cpp   |  121 +-
 libsanitizer/asan/asan_interceptors.h |   12 +
 .../asan/asan_interceptors_memintrinsics.cpp  |2 +-
 libsanitizer/asan/asan_mac.cpp|2 +-
 libsanitizer/asan/asan_malloc_linux.cpp   |2 +-
 libsanitizer/asan/asan_malloc_win.cpp |   11 +-
 libsanitizer/asan/asan_new_delete.cpp |2 +-
 libsanitizer/asan/asan_poisoning.cpp  |2 +-
 libsanitizer/asan/asan_report.cpp |   10 +-
 libsanitizer/asan/asan_rtems.cpp  |4 +-
 libsanitizer/asan/asan_rtl.cpp|6 +-
 libsanitizer/asan/asan_scariness_score.h  |2 +-
 libsanitizer/asan/asan_shadow_setup.cpp   |3 +-
 libsanitizer/asan/asan_stats.cpp  |2 +-
 libsanitizer/asan/asan_suppressions.cpp   |2 +-
 libsanitizer/asan/asan_thread.cpp |5 +-
 libsanitizer/asan/asan_win.cpp|   10 +-
 libsanitizer/asan/asan_win_dll_thunk.cpp  |8 +-
 .../asan/asan_win_dynamic_runtime_thunk.cpp   |   12 +-
 .../include/sanitizer/dfsan_interface.h   |2 +-
 .../include/sanitizer/tsan_interface_atomic.h |8 +-
 .../include/sanitizer/ubsan_interface.h   |   32 +
 libsanitizer/interception/interception.h  |4 +-
 .../interception/interception_win.cpp |8 +-
 libsanitizer/lsan/lsan.cpp|4 +-
 libsanitizer/lsan/lsan_common.cpp |   16 +-
 libsanitizer/lsan/lsan_common.h   |5 +-
 libsanitizer/lsan/lsan_common_linux.cpp   |   12 +-
 libsanitizer/lsan/lsan_common_mac.cpp |6 +-
 libsanitizer/lsan/lsan_interceptors.cpp   |   55 +
 libsanitizer/lsan/lsan_mac.cpp|2 +-
 .../sanitizer_allocator_checks.h  |2 +-
 .../sanitizer_allocator_report.cpp|9 +-
 libsanitizer/sanitizer_common/sanitizer_asm.h |4 +-
 .../sanitizer_common/sanitizer_atomic_msvc.h  |   63 +-
 .../sanitizer_common/sanitizer_common.cpp |2 +-
 .../sanitizer_common/sanitizer_common.h   |   25 +-
 .../sanitizer_common_interceptors.inc |  118 +-
 .../sanitizer_common_interface.inc|1 +
 .../sanitizer_coverage_fuchsia.cpp|6 +-
 .../sanitizer_coverage_libcdep_new.cpp|4 +-
 .../sanitizer_coverage_win_sections.cpp   |   12 +-
 .../sanitizer_common/sanitizer_file.cpp   |2 +-
 .../sanitizer_flag_parser.cpp |3 +-
 .../sanitizer_common/sanitizer_flag_parser.h  |4 +-
 .../sanitizer_common/sanitizer_flags.cpp  |4 +-
 .../sanitizer_common/sanitizer_fuchsia.cpp|2 +-
 .../sanitizer_common/sanitizer_getauxval.h|   30 +-
 .../sanitizer_glibc_version.h |   26 +
 .../sanitizer_interceptors_ioctl_netbsd.inc   |2 +-
 .../sanitizer_internal_defs.h |   75 +-
 .../sanitizer_common/sanitizer_libc.cpp   |   11 +-
 .../sanitizer_common/sanitizer_linux.cpp  |   39 +-
 .../sanitizer_linux_libcdep.cpp   |7 +-
 .../sanitizer_common/sanitizer_mac.cpp|  124 +-
 .../sanitizer_platform_interceptors.h |   24 +-
 .../sanitizer_platform_limits_freebsd.h   | 1090 -
 .../sanitizer_platform_limits_posix.cpp   |   15 +-
 .../sanitizer_platform_limits_posix.h | 2168 +
 .../sanitizer_platform_limits_solaris.h   |5 +-
 .../sanitizer_common/sanitizer_posix.cpp  |2 +
 .../sanitizer_common/sanitizer_posix.h|2 +-
 .../sanitizer_posix_libcdep.cpp   |   26 +-
 .../sanitizer_common/sanitizer_printf.cpp |6 +-
 .../sanitizer_common/sanitizer_procmaps.h |2

[PATCH 2/5] Update Makefile.am.

2019-11-05 Thread Martin Liska

libsanitizer/ChangeLog:

2019-11-05  Martin Liska  

* tsan/Makefile.am: Rename tsan_interceptors.cpp to
tsan_interceptors_posix.
* tsan/Makefile.in: Regenerate.
---
 libsanitizer/tsan/Makefile.am | 2 +-
 libsanitizer/tsan/Makefile.in | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libsanitizer/tsan/Makefile.am b/libsanitizer/tsan/Makefile.am
index 1ca9b68a3c5..5d37abd20de 100644
--- a/libsanitizer/tsan/Makefile.am
+++ b/libsanitizer/tsan/Makefile.am
@@ -20,7 +20,7 @@ tsan_files = \
 	tsan_fd.cpp \
 	tsan_flags.cpp \
 	tsan_ignoreset.cpp \
-	tsan_interceptors.cpp \
+	tsan_interceptors_posix.cpp \
 	tsan_interceptors_mac.cpp \
 	tsan_interface_ann.cpp \
 	tsan_interface_atomic.cpp \
diff --git a/libsanitizer/tsan/Makefile.in b/libsanitizer/tsan/Makefile.in
index cae00ab45ad..3d1d9565e47 100644
--- a/libsanitizer/tsan/Makefile.in
+++ b/libsanitizer/tsan/Makefile.in
@@ -146,7 +146,7 @@ LTLIBRARIES = $(toolexeclib_LTLIBRARIES)
 am__DEPENDENCIES_1 =
 am__objects_1 = tsan_clock.lo tsan_debugging.lo tsan_external.lo \
 	tsan_fd.lo tsan_flags.lo tsan_ignoreset.lo \
-	tsan_interceptors.lo tsan_interceptors_mac.lo \
+	tsan_interceptors_posix.lo tsan_interceptors_mac.lo \
 	tsan_interface_ann.lo tsan_interface_atomic.lo \
 	tsan_interface.lo tsan_interface_java.lo tsan_malloc_mac.lo \
 	tsan_md5.lo tsan_mman.lo tsan_mutex.lo tsan_mutexset.lo \
@@ -421,7 +421,7 @@ tsan_files = \
 	tsan_fd.cpp \
 	tsan_flags.cpp \
 	tsan_ignoreset.cpp \
-	tsan_interceptors.cpp \
+	tsan_interceptors_posix.cpp \
 	tsan_interceptors_mac.cpp \
 	tsan_interface_ann.cpp \
 	tsan_interface_atomic.cpp \
@@ -585,8 +585,8 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsan_fd.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsan_flags.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsan_ignoreset.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsan_interceptors.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsan_interceptors_mac.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsan_interceptors_posix.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsan_interface.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsan_interface_ann.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsan_interface_atomic.Plo@am__quote@


[PATCH 4/5] Set print_summary for UBSAN.

2019-11-05 Thread Martin Liska

libsanitizer/ChangeLog:

2019-11-05  Martin Liska  

* ubsan/ubsan_flags.cpp (InitializeFlags): Trunk decided to print
summary for all sanitizers, but we want to have UBSAN without it.
---
 libsanitizer/ubsan/ubsan_flags.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libsanitizer/ubsan/ubsan_flags.cpp b/libsanitizer/ubsan/ubsan_flags.cpp
index 721c2273f13..80de2a6d101 100644
--- a/libsanitizer/ubsan/ubsan_flags.cpp
+++ b/libsanitizer/ubsan/ubsan_flags.cpp
@@ -54,6 +54,7 @@ void InitializeFlags() {
   {
 CommonFlags cf;
 cf.CopyFrom(*common_flags());
+cf.print_summary = false;
 cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH");
 OverrideCommonFlags(cf);
   }


[PATCH 0/2] cgraph_node refactoring

2019-10-29 Thread Martin Liska
Hi.

The patch is about refactoring of cgraph_node where I removed
2 embedded structs with just few members.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

Martin Liska (2):
  Remove cgraph_global_info.
  Remove cgraph_local_info structure.

 gcc/cgraph.c   | 74 
 gcc/cgraph.h   | 79 ++
 gcc/cgraphbuild.c  |  2 +-
 gcc/cgraphclones.c | 28 +++--
 gcc/cgraphunit.c   | 23 +-
 gcc/combine.c  |  3 +-
 gcc/config/i386/i386.c | 13 +++---
 gcc/gimple-fold.c  |  4 +-
 gcc/ipa-comdats.c  |  8 ++--
 gcc/ipa-cp.c   | 20 -
 gcc/ipa-devirt.c   |  2 +-
 gcc/ipa-fnsummary.c| 28 ++---
 gcc/ipa-hsa.c  |  4 +-
 gcc/ipa-icf.c  |  2 +-
 gcc/ipa-inline-analysis.c  | 10 ++---
 gcc/ipa-inline-transform.c | 16 +++
 gcc/ipa-inline.c   | 86 +++---
 gcc/ipa-profile.c  | 12 +++---
 gcc/ipa-prop.c | 26 ++--
 gcc/ipa-pure-const.c   |  6 +--
 gcc/ipa-reference.c|  4 +-
 gcc/ipa-split.c|  4 +-
 gcc/ipa-sra.c  |  4 +-
 gcc/ipa-utils.c|  2 +-
 gcc/ipa-visibility.c   |  8 ++--
 gcc/ipa.c  | 22 +-
 gcc/lto-cgraph.c   | 42 +--
 gcc/lto/lto-partition.c|  6 +--
 gcc/lto/lto-symtab.c   |  4 +-
 gcc/multiple_target.c  |  4 +-
 gcc/omp-simd-clone.c   |  4 +-
 gcc/passes.c   |  2 +-
 gcc/symtab.c   |  6 +--
 gcc/trans-mem.c| 22 +-
 gcc/tree-inline.c  |  2 +-
 gcc/tree-ssa-structalias.c |  4 +-
 36 files changed, 285 insertions(+), 301 deletions(-)

-- 
2.23.0



[PATCH 2/2] Remove cgraph_local_info structure.

2019-10-29 Thread Martin Liska

gcc/ChangeLog:

2019-10-25  Martin Liska  

* cgraph.c (cgraph_node::local_info): Transform to ...
(cgraph_node::local_info_node): ... this.
(cgraph_node::dump): Remove cgraph_local_info and
put its fields directly into cgraph_node.
(cgraph_node::get_availability): Likewise.
(cgraph_node::make_local): Likewise.
(cgraph_node::verify_node): Likewise.
* cgraph.h (struct GTY): Likewise.
* cgraphclones.c (set_new_clone_decl_and_node_flags): Likewise.
(duplicate_thunk_for_node): Likewise.
(cgraph_node::create_clone): Likewise.
(cgraph_node::create_virtual_clone): Likewise.
(cgraph_node::create_version_clone): Likewise.
* cgraphunit.c (cgraph_node::reset): Likewise.
(cgraph_node::finalize_function): Likewise.
(cgraph_node::add_new_function): Likewise.
(analyze_functions): Likewise.
* combine.c (setup_incoming_promotions): Likewise.
* config/i386/i386.c (ix86_function_regparm): Likewise.
(ix86_function_sseregparm): Likewise.
(init_cumulative_args): Likewise.
* ipa-cp.c (determine_versionability): Likewise.
(count_callers): Likewise.
(set_single_call_flag): Likewise.
(initialize_node_lattices): Likewise.
(estimate_local_effects): Likewise.
(create_specialized_node): Likewise.
(identify_dead_nodes): Likewise.
* ipa-fnsummary.c (compute_fn_summary): Likewise.
(ipa_fn_summary_generate): Likewise.
* ipa-hsa.c (check_warn_node_versionable): Likewise.
(process_hsa_functions): Likewise.
* ipa-icf.c (set_local): Likewise.
* ipa-inline-analysis.c (initialize_inline_failed): Likewise.
* ipa-inline.c (speculation_useful_p): Likewise.
* ipa-profile.c (ipa_propagate_frequency): Likewise.
(ipa_profile): Likewise.
* ipa-split.c (split_function): Likewise.
(execute_split_functions): Likewise.
* ipa-sra.c (ipa_sra_preliminary_function_checks): Likewise.
(ipa_sra_ipa_function_checks): Likewise.
* ipa-visibility.c (function_and_variable_visibility): Likewise.
* ipa.c (symbol_table::remove_unreachable_nodes): Likewise.
* lto-cgraph.c (lto_output_node): Likewise.
(input_overwrite_node): Likewise.
* multiple_target.c (expand_target_clones): Likewise.
* omp-simd-clone.c (simd_clone_create): Likewise.
* trans-mem.c (expand_call_tm): Likewise.
(ipa_tm_mayenterirr_function): Likewise.
(ipa_tm_diagnose_tm_safe): Likewise.
(ipa_tm_diagnose_transaction): Likewise.
(ipa_tm_create_version): Likewise.
(ipa_tm_transform_calls_redirect): Likewise.
(ipa_tm_execute): Likewise.
* tree-inline.c (expand_call_inline): Likewise.
---
 gcc/cgraph.c  | 18 +-
 gcc/cgraph.h  | 40 ++-
 gcc/cgraphclones.c| 21 +++-
 gcc/cgraphunit.c  |  7 +++
 gcc/combine.c |  3 ++-
 gcc/config/i386/i386.c| 13 ++---
 gcc/ipa-cp.c  | 20 ++--
 gcc/ipa-fnsummary.c   | 10 +-
 gcc/ipa-hsa.c |  4 ++--
 gcc/ipa-icf.c |  2 +-
 gcc/ipa-inline-analysis.c |  2 +-
 gcc/ipa-inline.c  |  2 +-
 gcc/ipa-profile.c |  8 
 gcc/ipa-split.c   |  4 ++--
 gcc/ipa-sra.c |  4 ++--
 gcc/ipa-visibility.c  |  6 +++---
 gcc/ipa.c |  4 ++--
 gcc/lto-cgraph.c  | 16 
 gcc/multiple_target.c |  4 ++--
 gcc/omp-simd-clone.c  |  2 +-
 gcc/trans-mem.c   | 22 ++---
 gcc/tree-inline.c |  2 +-
 22 files changed, 102 insertions(+), 112 deletions(-)

diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 2dc91a3a99b..33fba5a8f1c 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -1834,16 +1834,16 @@ cgraph_node::mark_address_taken (void)
   node->address_taken = 1;
 }
 
-/* Return local info for the compiled function.  */
+/* Return local info node for the compiled function.  */
 
-cgraph_local_info *
-cgraph_node::local_info (tree decl)
+cgraph_node *
+cgraph_node::local_info_node (tree decl)
 {
   gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
   cgraph_node *node = get (decl);
   if (!node)
 return NULL;
-  return >ultimate_alias_target ()->local;
+  return node->ultimate_alias_target ();
 }
 
 /* Return RTL info for the compiled function.  */
@@ -1991,9 +1991,9 @@ cgraph_node::dump (FILE *f)
 fprintf (f, " body");
   if (process)
 fprintf (f, " process");
-  if (local.local)
+  if (local)
 fprintf (f, " local");
-  if (local.redefined_extern_inline)
+  if (redefined_extern_inline)
 fprintf (f, " redefined_extern_inline");
   if (only_called_at_startup)
 fprintf (f, " only_called_at_start

[PATCH 1/2] Remove cgraph_global_info.

2019-10-29 Thread Martin Liska
---
 gcc/cgraph.c   | 56 -
 gcc/cgraph.h   | 41 ---
 gcc/cgraphbuild.c  |  2 +-
 gcc/cgraphclones.c |  7 ++--
 gcc/cgraphunit.c   | 16 
 gcc/gimple-fold.c  |  4 +-
 gcc/ipa-comdats.c  |  8 ++--
 gcc/ipa-devirt.c   |  2 +-
 gcc/ipa-fnsummary.c| 18 
 gcc/ipa-inline-analysis.c  |  8 ++--
 gcc/ipa-inline-transform.c | 16 
 gcc/ipa-inline.c   | 84 +++---
 gcc/ipa-profile.c  |  4 +-
 gcc/ipa-prop.c | 26 ++--
 gcc/ipa-pure-const.c   |  6 +--
 gcc/ipa-reference.c|  4 +-
 gcc/ipa-utils.c|  2 +-
 gcc/ipa-visibility.c   |  2 +-
 gcc/ipa.c  | 18 
 gcc/lto-cgraph.c   | 26 ++--
 gcc/lto/lto-partition.c|  6 +--
 gcc/lto/lto-symtab.c   |  4 +-
 gcc/omp-simd-clone.c   |  2 +-
 gcc/passes.c   |  2 +-
 gcc/symtab.c   |  6 +--
 gcc/tree-ssa-structalias.c |  4 +-
 26 files changed, 184 insertions(+), 190 deletions(-)

diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index d47d4128b1c..2dc91a3a99b 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -539,7 +539,7 @@ cgraph_node::get_create (tree decl)
 {
   cgraph_node *first_clone = cgraph_node::get (decl);
 
-  if (first_clone && !first_clone->global.inlined_to)
+  if (first_clone && !first_clone->inlined_to)
 return first_clone;
 
   cgraph_node *node = cgraph_node::create (decl);
@@ -659,7 +659,7 @@ cgraph_node::get_for_asmname (tree asmname)
node = node->next_sharing_asm_name)
 {
   cgraph_node *cn = dyn_cast  (node);
-  if (cn && !cn->global.inlined_to)
+  if (cn && !cn->inlined_to)
 	return cn;
 }
   return NULL;
@@ -1786,7 +1786,7 @@ cgraph_node::remove (void)
 {
   cgraph_node *n = cgraph_node::get (decl);
   if (!n
-	  || (!n->clones && !n->clone_of && !n->global.inlined_to
+	  || (!n->clones && !n->clone_of && !n->inlined_to
 	  && ((symtab->global_info_ready || in_lto_p)
 		  && (TREE_ASM_WRITTEN (n->decl)
 		  || DECL_EXTERNAL (n->decl)
@@ -1817,7 +1817,7 @@ cgraph_node::mark_address_taken (void)
 {
   /* Indirect inlining can figure out that all uses of the address are
  inlined.  */
-  if (global.inlined_to)
+  if (inlined_to)
 {
   gcc_assert (cfun->after_inlining);
   gcc_assert (callers->indirect_inlining_edge);
@@ -1944,10 +1944,10 @@ cgraph_node::dump (FILE *f)
 
   dump_base (f);
 
-  if (global.inlined_to)
+  if (inlined_to)
 fprintf (f, "  Function %s is inline copy in %s\n",
 	 dump_name (),
-	 global.inlined_to->dump_name ());
+	 inlined_to->dump_name ());
   if (clone_of)
 fprintf (f, "  Clone of %s\n", clone_of->dump_asm_name ());
   if (symtab->function_flags_ready)
@@ -2096,7 +2096,7 @@ cgraph_node::dump (FILE *f)
 	if (dyn_cast  (ref->referring)->count.initialized_p ())
 	  sum += dyn_cast  (ref->referring)->count.ipa ();
   
-  if (global.inlined_to
+  if (inlined_to
 	  || (symtab->state < EXPANSION
 	  && ultimate_alias_target () == this && only_called_directly_p ()))
 	ok = !count.ipa ().differs_from_p (sum);
@@ -2212,14 +2212,14 @@ cgraph_node::get_availability (symtab_node *ref)
 {
   cgraph_node *cref = dyn_cast  (ref);
   if (cref)
-	ref = cref->global.inlined_to;
+	ref = cref->inlined_to;
 }
   enum availability avail;
   if (!analyzed)
 avail = AVAIL_NOT_AVAILABLE;
   else if (local.local)
 avail = AVAIL_LOCAL;
-  else if (global.inlined_to)
+  else if (inlined_to)
 avail = AVAIL_AVAILABLE;
   else if (transparent_alias)
 ultimate_alias_target (, ref);
@@ -2828,7 +2828,7 @@ bool
 cgraph_node::will_be_removed_from_program_if_no_direct_calls_p
 	 (bool will_inline)
 {
-  gcc_assert (!global.inlined_to);
+  gcc_assert (!inlined_to);
   if (DECL_EXTERNAL (decl))
 return true;
 
@@ -3015,7 +3015,7 @@ cgraph_edge::verify_corresponds_to_fndecl (tree decl)
 {
   cgraph_node *node;
 
-  if (!decl || callee->global.inlined_to)
+  if (!decl || callee->inlined_to)
 return false;
   if (symtab->state == LTO_STREAMING)
 return false;
@@ -3085,7 +3085,7 @@ cgraph_node::verify_node (void)
   error ("cgraph count invalid");
   error_found = true;
 }
-  if (global.inlined_to && same_comdat_group)
+  if (inlined_to && same_comdat_group)
 {
   error ("inline clone in same comdat group list");
   error_found = true;
@@ -3095,17 +3095,17 @@ cgraph_node::verify_node (void)
   error ("local symbols must be defined");
   error_found = true;
 }
-  if (global.inlined_to && externally_visible)
+  if (inlined_to && externally_visible)
 {
   error ("externally visible inline clone");
   error_found = true;
 }
-  if (global.inlined_to && address_taken)
+  if (inlined_to && address_taken)
 {
   error ("inline clone with address taken");
   error_found = true;
 }
- 

[PATCH 1/3] Remove misleading sorting function in ggc memory report.

2019-10-25 Thread Martin Liska

gcc/ChangeLog:

2019-10-25  Martin Liska  

* cgraphunit.c (symbol_table::compile): Remove argument
for dump_memory_report.
* ggc-common.c (dump_ggc_loc_statistics): Likewise.
(compare_final): Remove in order to make report
better readable.
* ggc.h (dump_ggc_loc_statistics):  Remove argument.
* mem-stats.h (mem_alloc_description::get_list):
Do not pass cmp.
(mem_alloc_description::dump): Likewise here.
* toplev.c (dump_memory_report): Remove final
argument.
(finalize): Likewise.
* toplev.h (dump_memory_report): Remove argument.

gcc/lto/ChangeLog:

2019-10-25  Martin Liska  

* lto.c (do_whole_program_analysis): Remove argument.
---
 gcc/cgraphunit.c |  4 ++--
 gcc/ggc-common.c | 19 ++-
 gcc/ggc.h|  2 +-
 gcc/lto/lto.c|  6 +++---
 gcc/mem-stats.h  | 19 ++-
 gcc/toplev.c |  6 +++---
 gcc/toplev.h |  2 +-
 7 files changed, 18 insertions(+), 40 deletions(-)

diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 3f751fa1044..9873b9b7aac 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -2604,7 +2604,7 @@ symbol_table::compile (void)
   if (pre_ipa_mem_report)
 {
   fprintf (stderr, "Memory consumption before IPA\n");
-  dump_memory_report (false);
+  dump_memory_report ();
 }
   if (!quiet_flag)
 fprintf (stderr, "Performing interprocedural optimizations\n");
@@ -2639,7 +2639,7 @@ symbol_table::compile (void)
   if (post_ipa_mem_report)
 {
   fprintf (stderr, "Memory consumption after IPA\n");
-  dump_memory_report (false);
+  dump_memory_report ();
 }
   timevar_pop (TV_CGRAPHOPT);
 
diff --git a/gcc/ggc-common.c b/gcc/ggc-common.c
index 0968d9769fa..8bc77a0a036 100644
--- a/gcc/ggc-common.c
+++ b/gcc/ggc-common.c
@@ -933,21 +933,6 @@ public:
 return s.second->get_balance () - f.second->get_balance ();
   }
 
-  /* Compare rows in final GGC summary dump.  */
-  static int
-  compare_final (const void *first, const void *second)
-  {
-typedef std::pair mem_pair_t;
-
-const ggc_usage *f = ((const mem_pair_t *)first)->second;
-const ggc_usage *s = ((const mem_pair_t *)second)->second;
-
-size_t a = f->m_allocated + f->m_overhead - f->m_freed;
-size_t b = s->m_allocated + s->m_overhead - s->m_freed;
-
-return a == b ? 0 : (a < b ? 1 : -1);
-  }
-
   /* Dump header with NAME.  */
   static inline void
   dump_header (const char *name)
@@ -970,7 +955,7 @@ static mem_alloc_description ggc_mem_desc;
 /* Dump per-site memory statistics.  */
 
 void
-dump_ggc_loc_statistics (bool final)
+dump_ggc_loc_statistics ()
 {
   if (! GATHER_STATISTICS)
 return;
@@ -978,7 +963,7 @@ dump_ggc_loc_statistics (bool final)
   ggc_force_collect = true;
   ggc_collect ();
 
-  ggc_mem_desc.dump (GGC_ORIGIN, final ? ggc_usage::compare_final : NULL);
+  ggc_mem_desc.dump (GGC_ORIGIN);
 
   ggc_force_collect = false;
 }
diff --git a/gcc/ggc.h b/gcc/ggc.h
index 31606dc843f..64d1f188eb0 100644
--- a/gcc/ggc.h
+++ b/gcc/ggc.h
@@ -149,7 +149,7 @@ extern void *ggc_realloc (void *, size_t CXX_MEM_STAT_INFO);
 /* Free a block.  To be used when known for certain it's not reachable.  */
 extern void ggc_free (void *);
 
-extern void dump_ggc_loc_statistics (bool);
+extern void dump_ggc_loc_statistics ();
 
 /* Reallocator.  */
 #define GGC_RESIZEVEC(T, P, N) \
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index 9b8c3272977..5dca73ffdb3 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -457,7 +457,7 @@ do_whole_program_analysis (void)
   if (pre_ipa_mem_report)
 {
   fprintf (stderr, "Memory consumption before IPA\n");
-  dump_memory_report (false);
+  dump_memory_report ();
 }
 
   symtab->function_flags_ready = true;
@@ -539,14 +539,14 @@ do_whole_program_analysis (void)
   if (post_ipa_mem_report)
 {
   fprintf (stderr, "Memory consumption after IPA\n");
-  dump_memory_report (false);
+  dump_memory_report ();
 }
 
   /* Show the LTO report before launching LTRANS.  */
   if (flag_lto_report || (flag_wpa && flag_lto_report_wpa))
 print_lto_report_1 ();
   if (mem_report_wpa)
-dump_memory_report (true);
+dump_memory_report ();
 }
 
 /* Create artificial pointers for "omp declare target link" vars.  */
diff --git a/gcc/mem-stats.h b/gcc/mem-stats.h
index 9ceb9ccc55b..c2329c2b14d 100644
--- a/gcc/mem-stats.h
+++ b/gcc/mem-stats.h
@@ -361,14 +361,11 @@ public:
  are filtered by ORIGIN type, LENGTH is return value where we register
  the number of elements in the list. If we want to process custom order,
  CMP comparator can be provided.  */
-  mem_list_t *get_list (mem_alloc_origin origin, unsigned *length,
-			int (*cmp) (const void *first,
-const void *second) = NULL);
+  mem_list_t *get_list (mem_alloc_origin origin, unsigned *l

[PATCH 3/3] Print header in dump_memory_report.

2019-10-25 Thread Martin Liska

gcc/ChangeLog:

2019-10-25  Martin Liska  

* cgraphunit.c (symbol_table::compile): Pass
title as dump_memory_report argument.
* toplev.c (dump_memory_report):  New argument.
(finalize): Pass new argument.
* toplev.h (dump_memory_report): Add argument.

gcc/lto/ChangeLog:

2019-10-25  Martin Liska  

* lto.c (do_whole_program_analysis): Pass
title as dump_memory_report argument.
---
 gcc/cgraphunit.c | 10 ++
 gcc/lto/lto.c| 12 +++-
 gcc/toplev.c | 13 +++--
 gcc/toplev.h |  3 ++-
 4 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 9873b9b7aac..6ec24432351 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -2602,10 +2602,7 @@ symbol_table::compile (void)
 
   timevar_push (TV_CGRAPHOPT);
   if (pre_ipa_mem_report)
-{
-  fprintf (stderr, "Memory consumption before IPA\n");
-  dump_memory_report ();
-}
+dump_memory_report ("Memory consumption before IPA");
   if (!quiet_flag)
 fprintf (stderr, "Performing interprocedural optimizations\n");
   state = IPA;
@@ -2637,10 +2634,7 @@ symbol_table::compile (void)
   symtab->dump (dump_file);
 }
   if (post_ipa_mem_report)
-{
-  fprintf (stderr, "Memory consumption after IPA\n");
-  dump_memory_report ();
-}
+dump_memory_report ("Memory consumption after IPA");
   timevar_pop (TV_CGRAPHOPT);
 
   /* Output everything.  */
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index 5dca73ffdb3..27ea341e04c 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -455,10 +455,7 @@ do_whole_program_analysis (void)
   timevar_push (TV_WHOPR_WPA);
 
   if (pre_ipa_mem_report)
-{
-  fprintf (stderr, "Memory consumption before IPA\n");
-  dump_memory_report ();
-}
+dump_memory_report ("Memory consumption before IPA");
 
   symtab->function_flags_ready = true;
 
@@ -537,16 +534,13 @@ do_whole_program_analysis (void)
   timevar_stop (TV_PHASE_STREAM_OUT);
 
   if (post_ipa_mem_report)
-{
-  fprintf (stderr, "Memory consumption after IPA\n");
-  dump_memory_report ();
-}
+dump_memory_report ("Memory consumption after IPA");
 
   /* Show the LTO report before launching LTRANS.  */
   if (flag_lto_report || (flag_wpa && flag_lto_report_wpa))
 print_lto_report_1 ();
   if (mem_report_wpa)
-dump_memory_report ();
+dump_memory_report ("Final");
 }
 
 /* Create artificial pointers for "omp declare target link" vars.  */
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 8a152b8e3b1..00a5e832126 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1994,8 +1994,17 @@ target_reinit (void)
 }
 
 void
-dump_memory_report ()
+dump_memory_report (const char *header)
 {
+  /* Print significant header.  */
+  fputc ('\n', stderr);
+  for (unsigned i = 0; i < 80; i++)
+fputc ('#', stderr);
+  fprintf (stderr, "\n# %-77s#\n", header);
+  for (unsigned i = 0; i < 80; i++)
+fputc ('#', stderr);
+  fputs ("\n\n", stderr);
+
   dump_line_table_statistics ();
   ggc_print_statistics ();
   stringpool_statistics ();
@@ -2058,7 +2067,7 @@ finalize (bool no_backend)
 }
 
   if (mem_report)
-dump_memory_report ();
+dump_memory_report ("Final");
 
   if (profile_report)
 dump_profile_report ();
diff --git a/gcc/toplev.h b/gcc/toplev.h
index 91e346570db..8814a5e11f8 100644
--- a/gcc/toplev.h
+++ b/gcc/toplev.h
@@ -66,7 +66,8 @@ extern bool wrapup_global_declarations (tree *, int);
 
 extern void global_decl_processing (void);
 
-extern void dump_memory_report ();
+extern void
+dump_memory_report (const char *);
 extern void dump_profile_report (void);
 
 extern void target_reinit (void);


[PATCH 0/3] -fmem-report tweaks

2019-10-25 Thread Martin Liska
Hi.

The patches fix 3 issues I spotted today during a LTO debugging
session:

1) Removal of two different sorting of GGC memory, it's confusing.
2) Move Leak to the first column for GGC memory similarly to
   other reports.
3) I make a significant header/title that can distinguish in between
   -fpre-ipa-mem-report and other options.

Thanks,
Martin

Martin Liska (3):
  Remove misleading sorting function in ggc memory report.
  Move Leak in GCC memory report to the first column.
  Print header in dump_memory_report.

 gcc/cgraphunit.c | 10 ++
 gcc/ggc-common.c | 28 +++-
 gcc/ggc.h|  2 +-
 gcc/lto/lto.c| 12 +++-
 gcc/mem-stats.h  | 19 ++-
 gcc/toplev.c | 15 ---
 gcc/toplev.h |  3 ++-
 7 files changed, 33 insertions(+), 56 deletions(-)

-- 
2.23.0



[PATCH 2/3] Move Leak in GCC memory report to the first column.

2019-10-25 Thread Martin Liska

gcc/ChangeLog:

2019-10-25  Martin Liska  

* ggc-common.c: Move Leak to the first column.
---
 gcc/ggc-common.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/ggc-common.c b/gcc/ggc-common.c
index 8bc77a0a036..37d3c5df9e1 100644
--- a/gcc/ggc-common.c
+++ b/gcc/ggc-common.c
@@ -887,10 +887,11 @@ public:
 fprintf (stderr,
 	 "%-48s " PRsa (9) ":%5.1f%%" PRsa (9) ":%5.1f%%"
 	 PRsa (9) ":%5.1f%%" PRsa (9) ":%5.1f%%" PRsa (9) "\n",
-	 prefix, SIZE_AMOUNT (m_collected),
+	 prefix,
+	 SIZE_AMOUNT (balance), get_percent (balance, total.get_balance ()),
+	 SIZE_AMOUNT (m_collected),
 	 get_percent (m_collected, total.m_collected),
 	 SIZE_AMOUNT (m_freed), get_percent (m_freed, total.m_freed),
-	 SIZE_AMOUNT (balance), get_percent (balance, total.get_balance ()),
 	 SIZE_AMOUNT (m_overhead),
 	 get_percent (m_overhead, total.m_overhead),
 	 SIZE_AMOUNT (m_times));
@@ -937,8 +938,8 @@ public:
   static inline void
   dump_header (const char *name)
   {
-fprintf (stderr, "%-48s %11s%17s%17s%16s%17s\n", name, "Garbage", "Freed",
-	 "Leak", "Overhead", "Times");
+fprintf (stderr, "%-48s %11s%17s%17s%16s%17s\n", name, "Leak", "Garbage",
+	 "Freed", "Overhead", "Times");
   }
 
   /* Freed memory in bytes.  */


[PATCH 2/2] Clean next_nested properly.

2019-08-14 Thread Martin Liska

gcc/ChangeLog:

2019-08-14  Martin Liska  

PR ipa/91438
* cgraph.c (cgraph_node::remove): When setting
n->origin = NULL for all nested functions, reset
also next_nested.
---
 gcc/cgraph.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index eb38b905879..ea8ab38d806 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -1767,8 +1767,6 @@ cgraph_node::release_body (bool keep_arguments)
 void
 cgraph_node::remove (void)
 {
-  cgraph_node *n;
-
   if (symtab->ipa_clones_dump_file && symtab->cloned_nodes.contains (this))
 fprintf (symtab->ipa_clones_dump_file,
 	 "Callgraph removal;%s;%d;%s;%d;%d\n", asm_name (), order,
@@ -1785,8 +1783,13 @@ cgraph_node::remove (void)
  */
   force_output = false;
   forced_by_abi = false;
-  for (n = nested; n; n = n->next_nested)
+  cgraph_node *next = nested;
+  for (cgraph_node *n = nested; n; n = next)
+  {
+next = n->next_nested;
 n->origin = NULL;
+n->next_nested = NULL;
+  }
   nested = NULL;
   if (origin)
 {
@@ -1840,7 +1843,7 @@ cgraph_node::remove (void)
  */
   if (symtab->state != LTO_STREAMING)
 {
-  n = cgraph_node::get (decl);
+  cgraph_node *n = cgraph_node::get (decl);
   if (!n
 	  || (!n->clones && !n->clone_of && !n->global.inlined_to
 	  && ((symtab->global_info_ready || in_lto_p)


[PATCH 1/2] Add ::verify for cgraph_node::origin/nested/next_nested.

2019-08-14 Thread Martin Liska

gcc/ChangeLog:

2019-08-14  Martin Liska  

* cgraph.c (cgraph_node::verify_node): Verify origin, nested
and next_nested.
---
 gcc/cgraph.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index ed46d81a513..eb38b905879 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -3464,6 +3464,30 @@ cgraph_node::verify_node (void)
 	  e->aux = 0;
 	}
 }
+
+  if (nested != NULL)
+{
+  for (cgraph_node *n = nested; n != NULL; n = n->next_nested)
+	{
+	  if (n->origin == NULL)
+	{
+	  error ("missing origin for a node in a nested list");
+	  error_found = true;
+	}
+	  else if (n->origin != this)
+	{
+	  error ("origin points to a different parent");
+	  error_found = true;
+	  break;
+	}
+	}
+}
+  if (next_nested != NULL && origin == NULL)
+{
+  error ("missing origin for a node in a nested list");
+  error_found = true;
+}
+
   if (error_found)
 {
   dump (stderr);


[PATCH 0/2] Fix dangling pointer in next_nested.

2019-08-14 Thread Martin Liska
Hi.

First patch is about addition of a nested/origin/next_nested verification.
The verification can find the issue in Ada run-time library on x86_64
without bootstrap.

The second patch is fix where we need to clean up the field.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

Martin Liska (2):
  Add ::verify for cgraph_node::origin/nested/next_nested.
  Clean next_nested properly.

 gcc/cgraph.c | 35 +++
 1 file changed, 31 insertions(+), 4 deletions(-)

-- 
2.22.0



[PATCH 0/3] Libsanitizer: merge from trunk

2019-08-13 Thread Martin Liska
Hi.

For this year, I decided to make a first merge now and the
next (much smaller) at the end of October.

The biggest change is rename of many files from .cc to .cpp.

I bootstrapped the patch set on x86_64-linux-gnu and run
asan/ubsan/tsan tests on x86_64, ppc64le (power8) and
aarch64.

Libasan SONAME has been already bumped compared to GCC 9.

For other libraries, I don't see a reason for library bumping:

$ abidiff /usr/lib64/libubsan.so.1.0.0 
./x86_64-pc-linux-gnu/libsanitizer/ubsan/.libs/libubsan.so.1.0.0 --stat
Functions changes summary: 0 Removed, 0 Changed, 4 Added functions
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable
Function symbols changes summary: 3 Removed, 0 Added function symbols not 
referenced by debug info
Variable symbols changes summary: 0 Removed, 0 Added variable symbol not 
referenced by debug info

$ abidiff /usr/lib64/libtsan.so.0.0.0  
./x86_64-pc-linux-gnu/libsanitizer/tsan/.libs/libtsan.so.0.0.0 --stat
Functions changes summary: 0 Removed, 0 Changed, 47 Added functions
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable
Function symbols changes summary: 1 Removed, 2 Added function symbols not 
referenced by debug info
Variable symbols changes summary: 0 Removed, 0 Added variable symbol not 
referenced by debug info

Ready to be installed?
Thanks,
Martin

Martin Liska (3):
  Libsanitizer merge from trunk r368656.
  Reapply all revisions mentioned in LOCAL_PATCHES.
  Fix a test-case scan pattern.

 gcc/testsuite/c-c++-common/asan/memcmp-1.c|4 +-
 libsanitizer/MERGE|2 +-
 libsanitizer/Makefile.in  |8 +-
 libsanitizer/aclocal.m4   |  191 +-
 libsanitizer/asan/Makefile.am |   63 +-
 libsanitizer/asan/Makefile.in |  323 +-
 ...asan_activation.cc => asan_activation.cpp} |7 +-
 libsanitizer/asan/asan_activation.h   |5 +-
 libsanitizer/asan/asan_activation_flags.inc   |5 +-
 .../{asan_allocator.cc => asan_allocator.cpp} |   18 +-
 libsanitizer/asan/asan_allocator.h|   44 +-
 .../{asan_debugging.cc => asan_debugging.cpp} |7 +-
 ..._descriptions.cc => asan_descriptions.cpp} |7 +-
 libsanitizer/asan/asan_descriptions.h |7 +-
 .../asan/{asan_errors.cc => asan_errors.cpp}  |   22 +-
 libsanitizer/asan/asan_errors.h   |   27 +-
 ...asan_fake_stack.cc => asan_fake_stack.cpp} |7 +-
 libsanitizer/asan/asan_fake_stack.h   |7 +-
 .../asan/{asan_flags.cc => asan_flags.cpp}|   13 +-
 libsanitizer/asan/asan_flags.h|5 +-
 libsanitizer/asan/asan_flags.inc  |9 +-
 .../{asan_fuchsia.cc => asan_fuchsia.cpp} |   20 +-
 .../{asan_globals.cc => asan_globals.cpp} |   31 +-
 ...an_globals_win.cc => asan_globals_win.cpp} |7 +-
 libsanitizer/asan/asan_init_version.h |5 +-
 ..._interceptors.cc => asan_interceptors.cpp} |   18 +-
 libsanitizer/asan/asan_interceptors.h |   39 +-
 ...cc => asan_interceptors_memintrinsics.cpp} |7 +-
 .../asan/asan_interceptors_memintrinsics.h|7 +-
 libsanitizer/asan/asan_interceptors_vfork.S   |   12 +
 libsanitizer/asan/asan_interface.inc  |6 +-
 libsanitizer/asan/asan_interface_internal.h   |7 +-
 libsanitizer/asan/asan_internal.h |   22 +-
 .../asan/{asan_linux.cc => asan_linux.cpp}|   14 +-
 .../asan/{asan_mac.cc => asan_mac.cpp}|   11 +-
 ..._malloc_linux.cc => asan_malloc_linux.cpp} |   17 +-
 libsanitizer/asan/asan_malloc_local.h |   30 +-
 ...asan_malloc_mac.cc => asan_malloc_mac.cpp} |   46 +-
 libsanitizer/asan/asan_malloc_win.cc  |  259 --
 libsanitizer/asan/asan_malloc_win.cpp |  553 
 libsanitizer/asan/asan_mapping.h  |   25 +-
 libsanitizer/asan/asan_mapping_myriad.h   |5 +-
 libsanitizer/asan/asan_mapping_sparc64.h  |5 +-
 ...ory_profile.cc => asan_memory_profile.cpp} |7 +-
 ...asan_new_delete.cc => asan_new_delete.cpp} |   37 +-
 .../{asan_poisoning.cc => asan_poisoning.cpp} |7 +-
 libsanitizer/asan/asan_poisoning.h|   15 +-
 .../asan/{asan_posix.cc => asan_posix.cpp}|   53 +-
 .../{asan_preinit.cc => asan_preinit.cpp} |7 +-
 ...remap_shadow.cc => asan_premap_shadow.cpp} |7 +-
 libsanitizer/asan/asan_premap_shadow.h|5 +-
 .../asan/{asan_report.cc => asan_report.cpp}  |   16 +-
 libsanitizer/asan/asan_report.h   |7 +-
 .../asan/{asan_rtems.cc => asan_rtems.cpp}|   17 +-
 .../asan/{asan_rtl.cc => asan_rtl.cpp}|   45 +-
 libsanitizer/asan/asan_scariness_score.h  |5 +-
 ..._shadow_setup.cc => asan_shadow_setup.cpp} |   11 +-
 libsanitizer/asan/asan_stack.cc   |   38 -
 libsanitizer/asan/asan_stack.cpp  |   88 +
 libsanitizer/asan/asan_stack.h|   47 +-
 .../asan/

[PATCH 2/3] Reapply all revisions mentioned in LOCAL_PATCHES.

2019-08-13 Thread Martin Liska

libsanitizer/ChangeLog:

2019-08-13  Martin Liska  

* asan/asan_globals.cpp (CheckODRViolationViaIndicator): Reapply
patch from trunk.
(CheckODRViolationViaPoisoning): Likewise.
(RegisterGlobal): Likewise.
* asan/asan_mapping.h: Likewise.
* sanitizer_common/sanitizer_linux_libcdep.cpp (defined): Likewise.
* sanitizer_common/sanitizer_mac.cpp (defined): Likewise.
* sanitizer_common/sanitizer_platform_limits_linux.cpp (defined): 
Likewise.
* sanitizer_common/sanitizer_platform_limits_posix.h (defined): 
Likewise.
* sanitizer_common/sanitizer_stacktrace.cpp (GetCanonicFrame): Likewise.
* ubsan/ubsan_handlers.cpp (__ubsan::__ubsan_handle_cfi_bad_icall): 
Likewise.
(__ubsan::__ubsan_handle_cfi_bad_icall_abort): Likewise.
* ubsan/ubsan_handlers.h (struct CFIBadIcallData): Likewise.
(struct CFICheckFailData): Likewise.
(RECOVERABLE): Likewise.
* ubsan/ubsan_platform.h: Likewise.
---
 libsanitizer/asan/asan_globals.cpp| 19 ---
 libsanitizer/asan/asan_mapping.h  |  2 +-
 .../sanitizer_linux_libcdep.cpp   |  4 
 .../sanitizer_common/sanitizer_mac.cpp|  2 +-
 .../sanitizer_platform_limits_linux.cpp   |  7 +--
 .../sanitizer_platform_limits_posix.h |  2 +-
 .../sanitizer_common/sanitizer_stacktrace.cpp | 17 -
 libsanitizer/ubsan/ubsan_handlers.cpp | 15 +++
 libsanitizer/ubsan/ubsan_handlers.h   |  8 
 libsanitizer/ubsan/ubsan_platform.h   |  2 ++
 10 files changed, 49 insertions(+), 29 deletions(-)

diff --git a/libsanitizer/asan/asan_globals.cpp b/libsanitizer/asan/asan_globals.cpp
index 54e75f3cee7..c77e5357bf9 100644
--- a/libsanitizer/asan/asan_globals.cpp
+++ b/libsanitizer/asan/asan_globals.cpp
@@ -154,23 +154,6 @@ static void CheckODRViolationViaIndicator(const Global *g) {
   }
 }
 
-// Check ODR violation for given global G by checking if it's already poisoned.
-// We use this method in case compiler doesn't use private aliases for global
-// variables.
-static void CheckODRViolationViaPoisoning(const Global *g) {
-  if (__asan_region_is_poisoned(g->beg, g->size_with_redzone)) {
-// This check may not be enough: if the first global is much larger
-// the entire redzone of the second global may be within the first global.
-for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) {
-  if (g->beg == l->g->beg &&
-  (flags()->detect_odr_violation >= 2 || g->size != l->g->size) &&
-  !IsODRViolationSuppressed(g->name))
-ReportODRViolation(g, FindRegistrationSite(g),
-   l->g, FindRegistrationSite(l->g));
-}
-  }
-}
-
 // Clang provides two different ways for global variables protection:
 // it can poison the global itself or its private alias. In former
 // case we may poison same symbol multiple times, that can help us to
@@ -216,8 +199,6 @@ static void RegisterGlobal(const Global *g) {
 // where two globals with the same name are defined in different modules.
 if (UseODRIndicator(g))
   CheckODRViolationViaIndicator(g);
-else
-  CheckODRViolationViaPoisoning(g);
   }
   if (CanPoisonMemory())
 PoisonRedZones(*g);
diff --git a/libsanitizer/asan/asan_mapping.h b/libsanitizer/asan/asan_mapping.h
index 41fb49ee46d..09be904270c 100644
--- a/libsanitizer/asan/asan_mapping.h
+++ b/libsanitizer/asan/asan_mapping.h
@@ -163,7 +163,7 @@ static const u64 kDefaultShort64bitShadowOffset =
 static const u64 kAArch64_ShadowOffset64 = 1ULL << 36;
 static const u64 kMIPS32_ShadowOffset32 = 0x0aaa;
 static const u64 kMIPS64_ShadowOffset64 = 1ULL << 37;
-static const u64 kPPC64_ShadowOffset64 = 1ULL << 44;
+static const u64 kPPC64_ShadowOffset64 = 1ULL << 41;
 static const u64 kSystemZ_ShadowOffset64 = 1ULL << 52;
 static const u64 kSPARC64_ShadowOffset64 = 1ULL << 43;  // 0x800
 static const u64 kFreeBSD_ShadowOffset32 = 1ULL << 30;  // 0x4000
diff --git a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
index 1f584a2add6..7dc38a0b703 100644
--- a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -701,9 +701,13 @@ u32 GetNumberOfCPUs() {
 #elif SANITIZER_SOLARIS
   return sysconf(_SC_NPROCESSORS_ONLN);
 #else
+#if defined(CPU_COUNT)
   cpu_set_t CPUs;
   CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), ), 0);
   return CPU_COUNT();
+#else
+  return 1;
+#endif
 #endif
 }
 
diff --git a/libsanitizer/sanitizer_common/sanitizer_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_mac.cpp
index bd6301aebad..7552b7aa965 100644
--- a/libsanitizer/sanitizer_common/sanitizer_mac.cpp
+++ b/libsanitizer/sanitizer_com

[PATCH 3/3] Fix a test-case scan pattern.

2019-08-13 Thread Martin Liska

gcc/testsuite/ChangeLog:

2019-08-13  Martin Liska  

* c-c++-common/asan/memcmp-1.c: There's a new function in the
stack-trace on the top.  So shift expected output in stack
trace.
---
 gcc/testsuite/c-c++-common/asan/memcmp-1.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/asan/memcmp-1.c b/gcc/testsuite/c-c++-common/asan/memcmp-1.c
index 5915988be5b..0a513c05ee1 100644
--- a/gcc/testsuite/c-c++-common/asan/memcmp-1.c
+++ b/gcc/testsuite/c-c++-common/asan/memcmp-1.c
@@ -16,5 +16,5 @@ main ()
 }
 
 /* { dg-output "ERROR: AddressSanitizer: stack-buffer-overflow.*(\n|\r\n|\r)" } */
-/* { dg-output "#0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)memcmp|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
-/* { dg-output "#1 0x\[0-9a-f\]+ +(in _*main|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "#1 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)memcmp|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "#2 0x\[0-9a-f\]+ +(in _*main|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */


[PATCH 1/3] Use argparse.ArgumentParser for mklog.

2019-08-13 Thread Martin Liska

contrib/ChangeLog:

2019-08-02  Martin Liska  

* mklog: Use argparse instead of getopt.
---
 contrib/mklog | 73 ++-
 1 file changed, 25 insertions(+), 48 deletions(-)

diff --git a/contrib/mklog b/contrib/mklog
index 15558cfbfe3..e7a513fad5c 100755
--- a/contrib/mklog
+++ b/contrib/mklog
@@ -28,11 +28,11 @@
 #
 # Author: Yury Gribov 
 
+import argparse
 import sys
 import re
 import os.path
 import os
-import getopt
 import tempfile
 import time
 import shutil
@@ -66,21 +66,6 @@ class RegexCache(object):
 
 cache = RegexCache()
 
-def print_help_and_exit():
-print("""\
-Usage: %s [-i | --inline] [PATCH]
-Generate ChangeLog template for PATCH.
-PATCH must be generated using diff(1)'s -up or -cp options
-(or their equivalent in Subversion/git).
-
-When PATCH is - or missing, read standard input.
-
-When -i is used, prepends ChangeLog to PATCH.
-If PATCH is not stdin, modifies PATCH in-place, otherwise writes
-to stdout.
-""" % me)
-sys.exit(1)
-
 def run(cmd, die_on_error):
   """Simple wrapper for Popen."""
   proc = Popen(cmd.split(' '), stderr = PIPE, stdout = PIPE)
@@ -356,38 +341,30 @@ def parse_patch(contents):
 def main():
   name, email = read_user_info()
 
-  try:
-opts, args = getopt.getopt(sys.argv[1:], 'hiv', ['help', 'verbose', 'inline'])
-  except getopt.GetoptError as err:
-error(str(err))
-
-  inline = False
-  verbose = 0
-
-  for o, a in opts:
-if o in ('-h', '--help'):
-  print_help_and_exit()
-elif o in ('-i', '--inline'):
-  inline = True
-elif o in ('-v', '--verbose'):
-  verbose += 1
-else:
-  assert False, "unhandled option"
-
-  if len(args) == 0:
-args = ['-']
+  help_message =  """\
+Generate ChangeLog template for PATCH.
+PATCH must be generated using diff(1)'s -up or -cp options
+(or their equivalent in Subversion/git).
+"""
 
-  if len(args) == 1 and args[0] == '-':
-input = sys.stdin
-  elif len(args) == 1:
-input = open(args[0])
-  else:
-error("too many arguments; for more details run with -h")
+  inline_message = """\
+Prepends ChangeLog to PATCH.
+If PATCH is not stdin, modifies PATCH in-place,
+otherwise writes to stdout.'
+"""
 
+  parser = argparse.ArgumentParser(description = help_message)
+  parser.add_argument('-v', '--verbose', action = 'store_true', help = 'Verbose messages')
+  parser.add_argument('-i', '--inline', action = 'store_true', help = inline_message)
+  parser.add_argument('input', nargs = '?', help = 'Patch file (or missing, read standard input)')
+  args = parser.parse_args()
+  if args.input == '-':
+  args.input = None
+  input = open(args.input) if args.input else sys.stdin
   contents = input.read()
   diffs = parse_patch(contents)
 
-  if verbose:
+  if args.verbose:
 print("Parse results:")
 for d in diffs:
   d.dump()
@@ -431,7 +408,7 @@ def main():
 
 logs[log_name] += change_msg if change_msg else ":\n"
 
-  if inline and args[0] != '-':
+  if args.inline and args.input:
 # Get a temp filename, rather than an open filehandle, because we use
 # the open to truncate.
 fd, tmp = tempfile.mkstemp("tmp.")
@@ -439,7 +416,7 @@ def main():
 
 # Copy permissions to temp file
 # (old Pythons do not support shutil.copymode)
-shutil.copymode(args[0], tmp)
+shutil.copymode(args.input, tmp)
 
 # Open the temp file, clearing contents.
 out = open(tmp, 'w')
@@ -457,14 +434,14 @@ def main():
 
 %s\n""" % (log_name, date, name, email, msg))
 
-  if inline:
+  if args.inline:
 # Append patch body
 out.write(contents)
 
-if args[0] != '-':
+if args.input:
   # Write new contents atomically
   out.close()
-  shutil.move(tmp, args[0])
+  shutil.move(tmp, args.input)
 
 if __name__ == '__main__':
 main()


[PATCH 2/3] mklog: parse PR references from new test files

2019-08-13 Thread Martin Liska

contrib/ChangeLog:

2019-08-13  Martin Liska  

* mklog: Parse PR references from newly added
test files.
---
 contrib/mklog | 22 --
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/contrib/mklog b/contrib/mklog
index e7a513fad5c..85242002357 100755
--- a/contrib/mklog
+++ b/contrib/mklog
@@ -40,6 +40,8 @@ from subprocess import Popen, PIPE
 
 me = os.path.basename(sys.argv[0])
 
+pr_regex = re.compile('\+(\/(\/|\*)|[Cc*!])\s+(PR [a-z+-]+\/[0-9]+)')
+
 def error(msg):
   sys.stderr.write("%s: error: %s\n" % (me, msg))
   sys.exit(1)
@@ -299,7 +301,7 @@ def parse_patch(contents):
 if l != r:
   break
 comps.append(l)
-
+
   if not comps:
 error("failed to extract common name for %s and %s" % (left, right))
 
@@ -338,6 +340,14 @@ def parse_patch(contents):
 
   return diffs
 
+
+def get_pr_from_testcase(line):
+r = pr_regex.search(line)
+if r != None:
+return r.group(3)
+else:
+return None
+
 def main():
   name, email = read_user_info()
 
@@ -372,6 +382,7 @@ otherwise writes to stdout.'
   # Generate template ChangeLog.
 
   logs = {}
+  prs = []
   for d in diffs:
 log_name = d.clname
 
@@ -387,6 +398,9 @@ otherwise writes to stdout.'
   if hunk0.is_file_addition():
 if re.search(r'testsuite.*(?
 
-%s\n""" % (log_name, date, name, email, msg))
+%s%s\n""" % (log_name, date, name, email, bugmsg, msg))
 
   if args.inline:
 # Append patch body


[PATCH 0/3] mklog improvements

2019-08-13 Thread Martin Liska
Hi.

I'm sending format independent changes to mklog that should
improve the script. It addresses couple of improvement
mentioned here:
https://gcc.gnu.org/ml/gcc-patches/2019-08/msg00031.html

Martin

Martin Liska (3):
  Use argparse.ArgumentParser for mklog.
  mklog: parse PR references from new test files
  mklog: Do not print changed functions in testsuite

 contrib/mklog | 98 ---
 1 file changed, 47 insertions(+), 51 deletions(-)

-- 
2.22.0



[PATCH 3/3] mklog: Do not print changed functions in testsuite

2019-08-13 Thread Martin Liska

contrib/ChangeLog:

2019-08-13  Martin Liska  

* mklog: Do not print changed functions for
testsuite files.
---
 contrib/mklog | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/mklog b/contrib/mklog
index 85242002357..1a0e82d1ddd 100755
--- a/contrib/mklog
+++ b/contrib/mklog
@@ -407,7 +407,8 @@ otherwise writes to stdout.'
 change_msg = ": Remove.\n"
 
 _, ext = os.path.splitext(d.filename)
-if not change_msg and ext in ['.c', '.cpp', '.C', '.cc', '.h', '.inc', '.def']:
+if (not change_msg and ext in ['.c', '.cpp', '.C', '.cc', '.h', '.inc', '.def']
+and not 'testsuite' in d.filename):
   fns = []
   for hunk in d.hunks:
 for fn in find_changed_funs(hunk):


[PATCH 6/9] Integrate that for IPA ICF.

2019-08-06 Thread Martin Liska

gcc/ChangeLog:

2019-07-24  Martin Liska  

* ipa-icf-gimple.c (func_checker::hash_operand_valueize): New
function created from compare_operand.
(func_checker::compare_cst_or_decl): Remove handling of
FIELD_DECLs as it's handled in operand_equal_p.
(func_checker::compare_operand): Transform
to func_checker::operand_equal_valueize.
(func_checker::operand_equal_valueize): New.
* ipa-icf-gimple.h (class func_checker): Inherit from
operand_compare.
* ipa-icf.c (sem_function::equals_private): Properly
set push_cfun and pop_cfun.
---
 gcc/ipa-icf-gimple.c | 226 +--
 gcc/ipa-icf-gimple.h |   8 +-
 gcc/ipa-icf.c|   7 +-
 3 files changed, 81 insertions(+), 160 deletions(-)

diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c
index 4060c0e8eb3..8448d387428 100644
--- a/gcc/ipa-icf-gimple.c
+++ b/gcc/ipa-icf-gimple.c
@@ -324,6 +324,28 @@ func_checker::compare_memory_operand (tree t1, tree t2)
 /* Function compare for equality given trees T1 and T2 which
can be either a constant or a declaration type.  */
 
+bool
+func_checker::hash_operand_valueize (const_tree arg, inchash::hash ,
+ unsigned int flags)
+{
+  switch (TREE_CODE (arg))
+{
+case FUNCTION_DECL:
+case VAR_DECL:
+case LABEL_DECL:
+case PARM_DECL:
+case RESULT_DECL:
+case CONST_DECL:
+case SSA_NAME:
+  return true;
+
+default:
+  break;
+}
+
+  return false;
+}
+
 bool
 func_checker::compare_cst_or_decl (tree t1, tree t2)
 {
@@ -347,19 +369,6 @@ func_checker::compare_cst_or_decl (tree t1, tree t2)
   return true;
 case VAR_DECL:
   return return_with_debug (compare_variable_decl (t1, t2));
-case FIELD_DECL:
-  {
-	tree offset1 = DECL_FIELD_OFFSET (t1);
-	tree offset2 = DECL_FIELD_OFFSET (t2);
-
-	tree bit_offset1 = DECL_FIELD_BIT_OFFSET (t1);
-	tree bit_offset2 = DECL_FIELD_BIT_OFFSET (t2);
-
-	ret = compare_operand (offset1, offset2)
-	  && compare_operand (bit_offset1, bit_offset2);
-
-	return return_with_debug (ret);
-  }
 case LABEL_DECL:
   {
 	if (t1 == t2)
@@ -383,165 +392,68 @@ func_checker::compare_cst_or_decl (tree t1, tree t2)
 }
 }
 
-/* Function responsible for comparison of various operands T1 and T2.
-   If these components, from functions FUNC1 and FUNC2, are equal, true
-   is returned.  */
-
-bool
-func_checker::compare_operand (tree t1, tree t2)
+int
+func_checker::operand_equal_valueize (const_tree ct1, const_tree ct2,
+  unsigned int)
 {
-  tree x1, x2, y1, y2, z1, z2;
-  bool ret;
-
-  if (!t1 && !t2)
-return true;
-  else if (!t1 || !t2)
-return false;
-
-  tree tt1 = TREE_TYPE (t1);
-  tree tt2 = TREE_TYPE (t2);
-
-  if (!func_checker::compatible_types_p (tt1, tt2))
-return false;
-
-  if (TREE_CODE (t1) != TREE_CODE (t2))
-return return_false ();
+  tree t1 = const_cast  (ct1);
+  tree t2 = const_cast  (ct2);
 
   switch (TREE_CODE (t1))
 {
-case CONSTRUCTOR:
+case FUNCTION_DECL:
+  /* All function decls are in the symbol table and known to match
+	 before we start comparing bodies.  */
+  return true;
+case VAR_DECL:
+  return return_with_debug (compare_variable_decl (t1, t2));
+case LABEL_DECL:
   {
-	unsigned length1 = CONSTRUCTOR_NELTS (t1);
-	unsigned length2 = CONSTRUCTOR_NELTS (t2);
-
-	if (length1 != length2)
-	  return return_false ();
-
-	for (unsigned i = 0; i < length1; i++)
-	  if (!compare_operand (CONSTRUCTOR_ELT (t1, i)->value,
-CONSTRUCTOR_ELT (t2, i)->value))
-	return return_false();
-
-	return true;
+	int *bb1 = m_label_bb_map.get (t1);
+	int *bb2 = m_label_bb_map.get (t2);
+	/* Labels can point to another function (non-local GOTOs).  */
+	return return_with_debug (bb1 != NULL && bb2 != NULL && *bb1 == *bb2);
   }
-case ARRAY_REF:
-case ARRAY_RANGE_REF:
-  /* First argument is the array, second is the index.  */
-  x1 = TREE_OPERAND (t1, 0);
-  x2 = TREE_OPERAND (t2, 0);
-  y1 = TREE_OPERAND (t1, 1);
-  y2 = TREE_OPERAND (t2, 1);
-
-  if (!compare_operand (array_ref_low_bound (t1),
-			array_ref_low_bound (t2)))
-	return return_false_with_msg ("");
-  if (!compare_operand (array_ref_element_size (t1),
-			array_ref_element_size (t2)))
-	return return_false_with_msg ("");
-
-  if (!compare_operand (x1, x2))
-	return return_false_with_msg ("");
-  return compare_operand (y1, y2);
-case MEM_REF:
-  {
-	x1 = TREE_OPERAND (t1, 0);
-	x2 = TREE_OPERAND (t2, 0);
-	y1 = TREE_OPERAND (t1, 1);
-	y2 = TREE_OPERAND (t2, 1);
-
-	/* See if operand is an memory access (the test originate from
-	 gimple_load_p).
-
-	In this case the alias set of the function being replaced must
-	be subset of the alias set of the other function.  At the moment
-	we seek for equivalency classes, so si

[PATCH 1/9] Replace int with boolean in predicate functions.

2019-08-06 Thread Martin Liska

gcc/ChangeLog:

2019-07-24  Martin Liska  

* fold-const.c (twoval_comparison_p): Replace int
with bool as a return type.
(simple_operand_p): Likewise.
(operand_equal_p): Replace int with bool as a return type.
* fold-const.h (operand_equal_p): Likewise.
---
 gcc/fold-const.c | 148 +++
 gcc/fold-const.h |   2 +-
 2 files changed, 75 insertions(+), 75 deletions(-)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 716d7397b49..0bd68b5e2d4 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -115,11 +115,11 @@ static tree negate_expr (tree);
 static tree associate_trees (location_t, tree, tree, enum tree_code, tree);
 static enum comparison_code comparison_to_compcode (enum tree_code);
 static enum tree_code compcode_to_comparison (enum comparison_code);
-static int twoval_comparison_p (tree, tree *, tree *);
+static bool twoval_comparison_p (tree, tree *, tree *);
 static tree eval_subst (location_t, tree, tree, tree, tree, tree);
 static tree optimize_bit_field_compare (location_t, enum tree_code,
 	tree, tree, tree);
-static int simple_operand_p (const_tree);
+static bool simple_operand_p (const_tree);
 static bool simple_operand_p_2 (tree);
 static tree range_binop (enum tree_code, tree, tree, int, tree, int);
 static tree range_predecessor (tree);
@@ -2939,7 +2939,7 @@ combine_comparisons (location_t loc,
addresses with TREE_CONSTANT flag set so we know that  == 
even if var is volatile.  */
 
-int
+bool
 operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
 {
   /* When checking, verify at the outermost operand_equal_p call that
@@ -2958,10 +2958,10 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
 	  hashval_t h1 = hstate1.end ();
 	  gcc_assert (h0 == h1);
 	}
-	  return 1;
+	  return true;
 	}
   else
-	return 0;
+	return false;
 }
 
   STRIP_ANY_LOCATION_WRAPPER (arg0);
@@ -2971,19 +2971,19 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
   if (TREE_CODE (arg0) == ERROR_MARK || TREE_CODE (arg1) == ERROR_MARK
   || TREE_TYPE (arg0) == error_mark_node
   || TREE_TYPE (arg1) == error_mark_node)
-return 0;
+return false;
 
   /* Similar, if either does not have a type (like a template id),
  they aren't equal.  */
   if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1))
-return 0;
+return false;
 
   /* We cannot consider pointers to different address space equal.  */
   if (POINTER_TYPE_P (TREE_TYPE (arg0))
   && POINTER_TYPE_P (TREE_TYPE (arg1))
   && (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg0)))
 	  != TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg1)
-return 0;
+return false;
 
   /* Check equality of integer constants before bailing out due to
  precision differences.  */
@@ -3005,13 +3005,13 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
   if (TYPE_UNSIGNED (TREE_TYPE (arg0)) != TYPE_UNSIGNED (TREE_TYPE (arg1))
 	  || POINTER_TYPE_P (TREE_TYPE (arg0))
 			 != POINTER_TYPE_P (TREE_TYPE (arg1)))
-	return 0;
+	return false;
 
   /* If both types don't have the same precision, then it is not safe
 	 to strip NOPs.  */
   if (element_precision (TREE_TYPE (arg0))
 	  != element_precision (TREE_TYPE (arg1)))
-	return 0;
+	return false;
 
   STRIP_NOPS (arg0);
   STRIP_NOPS (arg1);
@@ -3058,17 +3058,17 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
 	  && TREE_CODE (TREE_OPERAND (arg0, 0)) == ADDR_EXPR
 	  && TREE_OPERAND (TREE_OPERAND (arg0, 0), 0) == arg1
 	  && integer_zerop (TREE_OPERAND (arg0, 1)))
-	return 1;
+	return true;
 	  else if (TREE_CODE (arg1) == MEM_REF
 		   && DECL_P (arg0)
 		   && TREE_CODE (TREE_OPERAND (arg1, 0)) == ADDR_EXPR
 		   && TREE_OPERAND (TREE_OPERAND (arg1, 0), 0) == arg0
 		   && integer_zerop (TREE_OPERAND (arg1, 1)))
-	return 1;
-	  return 0;
+	return true;
+	  return false;
 	}
   else
-	return 0;
+	return false;
 }
 
   /* When not checking adddresses, this is needed for conversions and for
@@ -3077,7 +3077,7 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
   || TREE_CODE (TREE_TYPE (arg1)) == ERROR_MARK
   || (TYPE_MODE (TREE_TYPE (arg0)) != TYPE_MODE (TREE_TYPE (arg1))
 	  && !(flags & OEP_ADDRESS_OF)))
-return 0;
+return false;
 
   /* If ARG0 and ARG1 are the same SAVE_EXPR, they are necessarily equal.
  We don't care about side effects in that case because the SAVE_EXPR
@@ -3092,7 +3092,7 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
   && (TREE_CODE (arg0) == SAVE_EXPR
 	  || (flags & OEP_MATCH_SIDE_EFFECTS)
 	  || (! TREE_SIDE_EFFECTS (arg0) && ! TREE_SIDE_EFFECTS (arg1
-return 1;
+return true;
 
   /* Next handle

[PATCH 5/9] Come up with an abstraction.

2019-08-06 Thread Martin Liska

gcc/ChangeLog:

2019-07-24  Martin Liska  

* fold-const.c (operand_equal_p): Rename to ...
(operand_compare::operand_equal_p): ... this.
(add_expr):  Rename to ...
(operand_compare::hash_operand): ... this.
(operand_compare::operand_equal_valueize): Likewise.
(operand_compare::hash_operand_valueize): Likewise.
* fold-const.h (operand_equal_p): Set default
value for last argument.
(class operand_compare): New.
* tree.c (add_expr): Move content to hash_operand.
---
 gcc/fold-const.c | 346 ++-
 gcc/fold-const.h |  30 +++-
 gcc/tree.c   | 286 ---
 3 files changed, 372 insertions(+), 290 deletions(-)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 4bcde22ada7..087c450cace 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -2940,7 +2940,8 @@ combine_comparisons (location_t loc,
even if var is volatile.  */
 
 bool
-operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
+operand_compare::operand_equal_p (const_tree arg0, const_tree arg1,
+  unsigned int flags)
 {
   /* When checking, verify at the outermost operand_equal_p call that
  if operand_equal_p returns non-zero then ARG0 and ARG1 has the same
@@ -2952,8 +2953,8 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
 	  if (arg0 != arg1)
 	{
 	  inchash::hash hstate0 (0), hstate1 (0);
-	  inchash::add_expr (arg0, hstate0, flags | OEP_HASH_CHECK);
-	  inchash::add_expr (arg1, hstate1, flags | OEP_HASH_CHECK);
+	  hash_operand (arg0, hstate0, flags | OEP_HASH_CHECK);
+	  hash_operand (arg1, hstate1, flags | OEP_HASH_CHECK);
 	  hashval_t h0 = hstate0.end ();
 	  hashval_t h1 = hstate1.end ();
 	  gcc_assert (h0 == h1);
@@ -3094,6 +3095,12 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
 	  || (! TREE_SIDE_EFFECTS (arg0) && ! TREE_SIDE_EFFECTS (arg1
 return true;
 
+  int val = operand_equal_valueize (arg0, arg1, flags);
+  if (val == 1)
+return 1;
+  if (val == 0)
+return 0;
+
   /* Next handle constant cases, those for which we can return 1 even
  if ONLY_CONST is set.  */
   if (TREE_CONSTANT (arg0) && TREE_CONSTANT (arg1))
@@ -3605,6 +3612,339 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
 
 #undef OP_SAME
 #undef OP_SAME_WITH_NULL
+}
+
+/* Generate a hash value for an expression.  This can be used iteratively
+   by passing a previous result as the HSTATE argument.  */
+
+void
+operand_compare::hash_operand (const_tree t, inchash::hash ,
+			   unsigned int flags)
+{
+  int i;
+  enum tree_code code;
+  enum tree_code_class tclass;
+
+  if (t == NULL_TREE || t == error_mark_node)
+{
+  hstate.merge_hash (0);
+  return;
+}
+
+  STRIP_ANY_LOCATION_WRAPPER (t);
+
+  if (!(flags & OEP_ADDRESS_OF))
+STRIP_NOPS (t);
+
+  code = TREE_CODE (t);
+
+  bool ret = hash_operand_valueize (t, hstate, flags);
+  if (ret)
+return;
+
+  switch (code)
+{
+/* Alas, constants aren't shared, so we can't rely on pointer
+   identity.  */
+case VOID_CST:
+  hstate.merge_hash (0);
+  return;
+case INTEGER_CST:
+  gcc_checking_assert (!(flags & OEP_ADDRESS_OF));
+  for (i = 0; i < TREE_INT_CST_EXT_NUNITS (t); i++)
+	hstate.add_hwi (TREE_INT_CST_ELT (t, i));
+  return;
+case REAL_CST:
+  {
+	unsigned int val2;
+	if (!HONOR_SIGNED_ZEROS (t) && real_zerop (t))
+	  val2 = rvc_zero;
+	else
+	  val2 = real_hash (TREE_REAL_CST_PTR (t));
+	hstate.merge_hash (val2);
+	return;
+  }
+case FIXED_CST:
+  {
+	unsigned int val2 = fixed_hash (TREE_FIXED_CST_PTR (t));
+	hstate.merge_hash (val2);
+	return;
+  }
+case STRING_CST:
+  hstate.add ((const void *) TREE_STRING_POINTER (t),
+		  TREE_STRING_LENGTH (t));
+  return;
+case COMPLEX_CST:
+  hash_operand (TREE_REALPART (t), hstate, flags);
+  hash_operand (TREE_IMAGPART (t), hstate, flags);
+  return;
+case VECTOR_CST:
+  {
+	hstate.add_int (VECTOR_CST_NPATTERNS (t));
+	hstate.add_int (VECTOR_CST_NELTS_PER_PATTERN (t));
+	unsigned int count = vector_cst_encoded_nelts (t);
+	for (unsigned int i = 0; i < count; ++i)
+	  hash_operand (VECTOR_CST_ENCODED_ELT (t, i), hstate, flags);
+	return;
+  }
+case SSA_NAME:
+  /* We can just compare by pointer.  */
+  hstate.add_hwi (SSA_NAME_VERSION (t));
+  return;
+case PLACEHOLDER_EXPR:
+  /* The node itself doesn't matter.  */
+  return;
+case BLOCK:
+case OMP_CLAUSE:
+  /* Ignore.  */
+  return;
+case TREE_LIST:
+  /* A list of expressions, for a CALL_EXPR or as the elements of a
+	 VECTOR_CST.  */
+  for (; t; t = TREE_CHAIN (t))
+	hash_operand (TREE_VALUE (t), hstate, flags);
+  return;
+case CONSTRUCTOR:
+  {
+	unsigned HOST_WIDE

[PATCH 9/9] Remove alias set comparison.

2019-08-06 Thread Martin Liska

gcc/ChangeLog:

2019-07-24  Martin Liska  

* ipa-icf-gimple.c (func_checker::compatible_types_p):
Do not compare alias sets.  It's handled by operand_equal_p.

gcc/testsuite/ChangeLog:

2019-07-24  Martin Liska  

* c-c++-common/Wstringop-truncation-4.c: Disable IPA ICF.
* gcc.dg/tree-ssa/pr64910-2.c: Likewise.
* gcc.dg/tree-ssa/pr79352.c: Likewise.
* gcc.dg/ipa/ipa-icf-40.c: New test.
---
 gcc/ipa-icf-gimple.c  | 12 ---
 .../c-c++-common/Wstringop-truncation-4.c |  2 +-
 gcc/testsuite/gcc.dg/ipa/ipa-icf-40.c | 32 +++
 gcc/testsuite/gcc.dg/tree-ssa/pr64910-2.c |  2 +-
 gcc/testsuite/gcc.dg/tree-ssa/pr79352.c   |  2 +-
 5 files changed, 35 insertions(+), 15 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/ipa-icf-40.c

diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c
index 375aadad412..751d5859706 100644
--- a/gcc/ipa-icf-gimple.c
+++ b/gcc/ipa-icf-gimple.c
@@ -31,7 +31,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "cgraph.h"
 #include "data-streamer.h"
 #include "gimple-pretty-print.h"
-#include "alias.h"
 #include "fold-const.h"
 #include "gimple-iterator.h"
 #include "ipa-utils.h"
@@ -209,17 +208,6 @@ func_checker::compatible_types_p (tree t1, tree t2)
   if (!types_compatible_p (t1, t2))
 return return_false_with_msg ("types are not compatible");
 
-  /* We do a lot of unnecesary matching of types that are not being
- accessed and thus do not need to be compatible.  In longer term we should
- remove these checks on all types which are not accessed as memory
- locations.
-
- For time being just avoid calling get_alias_set on types that are not
- having alias sets defined at all.  */
-  if (type_with_alias_set_p (t1) && type_with_alias_set_p (t2)
-  && get_alias_set (t1) != get_alias_set (t2))
-return return_false_with_msg ("alias sets are different");
-
   return true;
 }
 
diff --git a/gcc/testsuite/c-c++-common/Wstringop-truncation-4.c b/gcc/testsuite/c-c++-common/Wstringop-truncation-4.c
index c76f2823daf..15209536add 100644
--- a/gcc/testsuite/c-c++-common/Wstringop-truncation-4.c
+++ b/gcc/testsuite/c-c++-common/Wstringop-truncation-4.c
@@ -3,7 +3,7 @@
Verify that -Wstringop-truncation is issued for uses of arrays and
pointers to qualified forms of characters of all three types.
{ dg-do compile }
-   { dg-options "-O2 -Wall -Wstringop-truncation" } */
+   { dg-options "-O2 -Wall -Wstringop-truncation -fno-ipa-icf" } */
 
 #if __cplusplus
 extern "C"
diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-icf-40.c b/gcc/testsuite/gcc.dg/ipa/ipa-icf-40.c
new file mode 100644
index 000..8d512cbc7d3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/ipa-icf-40.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf"  } */
+
+struct A { int i; char a1[10]; };
+struct B { int i; char a3[30]; };
+struct C { int i; char ax[]; };
+
+static int
+__attribute__((noinline))
+test_array_1 (int i, struct A *a)
+{
+  return __builtin_printf ("%-s\n", a->a1);
+}
+
+static int
+__attribute__((noinline))
+test_array_3 (int i, struct B *b)
+{
+  return __builtin_printf ("%-s\n", b->a3);
+}
+
+struct A a = { 0, "foo" };
+struct B b = { 0, "bar" };
+
+int main()
+{
+  test_array_1 (0, );
+  test_array_3 (0, );
+  return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf"  } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr64910-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr64910-2.c
index 2e3d6790776..812bfa48825 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr64910-2.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr64910-2.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-reassoc1" } */
+/* { dg-options "-O2 -fdump-tree-reassoc1 -fno-ipa-icf" } */
 
 /* We want to make sure that we reassociate in a way that has the
constant last.  With the constant last, it's more likely to result
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr79352.c b/gcc/testsuite/gcc.dg/tree-ssa/pr79352.c
index 485e2d64cb3..36e195c3a06 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr79352.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr79352.c
@@ -1,7 +1,7 @@
 /* PR tree-optimization/79352 - -fprintf-return-value doesn't handle
flexible-like array members properly
{ dg-do compile }
-   { dg-options "-O2 -fdump-tree-optimized" } */
+   { dg-options "-O2 -fdump-tree-optimized -fno-ipa-icf" } */
 
 struct A { int i; char a1[1]; };
 struct B { int i; char a3[3]; };


[PATCH 7/9] IPA ICF: remove dead code

2019-08-06 Thread Martin Liska

gcc/ChangeLog:

2019-07-24  Martin Liska  

* ipa-icf-gimple.c (func_checker::compare_ssa_name): Call
compare_operand.
(func_checker::compare_memory_operand): Remove.
(func_checker::compare_cst_or_decl): Remove.
(func_checker::operand_equal_valueize): Do not handle
FIELD_DECL.
(func_checker::compare_gimple_call): Call compare_operand.
(func_checker::compare_gimple_assign): Likewise.
* ipa-icf-gimple.h: Remove compare_cst_or_decl.
* ipa-icf.c (sem_function::icf_handled_component_p): Remove.
* ipa-icf.h (icf_handled_component_p): Remove.
---
 gcc/ipa-icf-gimple.c | 150 ++-
 gcc/ipa-icf-gimple.h |   4 --
 gcc/ipa-icf.c|  11 
 gcc/ipa-icf.h|   3 -
 4 files changed, 6 insertions(+), 162 deletions(-)

diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c
index 8448d387428..2d4c5d22534 100644
--- a/gcc/ipa-icf-gimple.c
+++ b/gcc/ipa-icf-gimple.c
@@ -111,13 +111,7 @@ func_checker::compare_ssa_name (tree t1, tree t2)
   tree b1 = SSA_NAME_VAR (t1);
   tree b2 = SSA_NAME_VAR (t2);
 
-  if (b1 == NULL && b2 == NULL)
-	return true;
-
-  if (b1 == NULL || b2 == NULL || TREE_CODE (b1) != TREE_CODE (b2))
-	return return_false ();
-
-  return compare_cst_or_decl (b1, b2);
+  return compare_operand (b1, b2);
 }
 
   return true;
@@ -247,86 +241,12 @@ func_checker::compatible_types_p (tree t1, tree t2)
   return true;
 }
 
-/* Function compare for equality given memory operands T1 and T2.  */
-
-bool
-func_checker::compare_memory_operand (tree t1, tree t2)
-{
-  if (!t1 && !t2)
-return true;
-  else if (!t1 || !t2)
-return false;
-
-  ao_ref r1, r2;
-  ao_ref_init (, t1);
-  ao_ref_init (, t2);
-
-  tree b1 = ao_ref_base ();
-  tree b2 = ao_ref_base ();
-
-  bool source_is_memop = DECL_P (b1) || INDIRECT_REF_P (b1)
-			 || TREE_CODE (b1) == MEM_REF
-			 || TREE_CODE (b1) == TARGET_MEM_REF;
-
-  bool target_is_memop = DECL_P (b2) || INDIRECT_REF_P (b2)
-			 || TREE_CODE (b2) == MEM_REF
-			 || TREE_CODE (b2) == TARGET_MEM_REF;
-
-  /* Compare alias sets for memory operands.  */
-  if (source_is_memop && target_is_memop)
-{
-  if (TREE_THIS_VOLATILE (t1) != TREE_THIS_VOLATILE (t2))
-	return return_false_with_msg ("different operand volatility");
-
-  if (ao_ref_alias_set () != ao_ref_alias_set ()
-	  || ao_ref_base_alias_set () != ao_ref_base_alias_set ())
-	return return_false_with_msg ("ao alias sets are different");
-
-  /* We can't simply use get_object_alignment_1 on the full
- reference as for accesses with variable indexes this reports
-	 too conservative alignment.  We also can't use the ao_ref_base
-	 base objects as ao_ref_base happily strips MEM_REFs around
-	 decls even though that may carry alignment info.  */
-  b1 = t1;
-  while (handled_component_p (b1))
-	b1 = TREE_OPERAND (b1, 0);
-  b2 = t2;
-  while (handled_component_p (b2))
-	b2 = TREE_OPERAND (b2, 0);
-  unsigned int align1, align2;
-  unsigned HOST_WIDE_INT tem;
-  get_object_alignment_1 (b1, , );
-  get_object_alignment_1 (b2, , );
-  if (align1 != align2)
-	return return_false_with_msg ("different access alignment");
-
-  /* Similarly we have to compare dependence info where equality
- tells us we are safe (even some unequal values would be safe
-	 but then we have to maintain a map of bases and cliques).  */
-  unsigned short clique1 = 0, base1 = 0, clique2 = 0, base2 = 0;
-  if (TREE_CODE (b1) == MEM_REF)
-	{
-	  clique1 = MR_DEPENDENCE_CLIQUE (b1);
-	  base1 = MR_DEPENDENCE_BASE (b1);
-	}
-  if (TREE_CODE (b2) == MEM_REF)
-	{
-	  clique2 = MR_DEPENDENCE_CLIQUE (b2);
-	  base2 = MR_DEPENDENCE_BASE (b2);
-	}
-  if (clique1 != clique2 || base1 != base2)
-	return return_false_with_msg ("different dependence info");
-}
-
-  return compare_operand (t1, t2);
-}
-
 /* Function compare for equality given trees T1 and T2 which
can be either a constant or a declaration type.  */
 
 bool
-func_checker::hash_operand_valueize (const_tree arg, inchash::hash ,
- unsigned int flags)
+func_checker::hash_operand_valueize (const_tree arg, inchash::hash &,
+ unsigned int)
 {
   switch (TREE_CODE (arg))
 {
@@ -346,52 +266,6 @@ func_checker::hash_operand_valueize (const_tree arg, inchash::hash ,
   return false;
 }
 
-bool
-func_checker::compare_cst_or_decl (tree t1, tree t2)
-{
-  bool ret;
-
-  switch (TREE_CODE (t1))
-{
-case INTEGER_CST:
-case COMPLEX_CST:
-case VECTOR_CST:
-case STRING_CST:
-case REAL_CST:
-  {
-	ret = compatible_types_p (TREE_TYPE (t1), TREE_TYPE (t2))
-	  && operand_equal_p (t1, t2, OEP_ONLY_CONST);
-	return return_with_debug (ret);
-  }
-case FUNCTION_DECL:
-  /* All function decls are in the symbol table and known to match
-	 

[PATCH 8/9] Remove comparison for polymorphic types.

2019-08-06 Thread Martin Liska

gcc/ChangeLog:

2019-07-24  Martin Liska  

* ipa-icf-gimple.c (func_checker::func_checker): Do not
initialize m_compare_polymorphic.
(func_checker::compare_decl): Do not compare polymorphic types.
* ipa-icf-gimple.h (m_compare_polymorphic): Remove.
* ipa-icf.c (sem_function::equals_private): Do not call
compare_polymorphic_p.
---
 gcc/ipa-icf-gimple.c | 18 --
 gcc/ipa-icf-gimple.h |  4 
 gcc/ipa-icf.c|  1 -
 3 files changed, 23 deletions(-)

diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c
index 2d4c5d22534..375aadad412 100644
--- a/gcc/ipa-icf-gimple.c
+++ b/gcc/ipa-icf-gimple.c
@@ -51,14 +51,12 @@ namespace ipa_icf_gimple {
of declarations that can be skipped.  */
 
 func_checker::func_checker (tree source_func_decl, tree target_func_decl,
-			bool compare_polymorphic,
 			bool ignore_labels,
 			hash_set *ignored_source_nodes,
 			hash_set *ignored_target_nodes)
   : m_source_func_decl (source_func_decl), m_target_func_decl (target_func_decl),
 m_ignored_source_nodes (ignored_source_nodes),
 m_ignored_target_nodes (ignored_target_nodes),
-m_compare_polymorphic (compare_polymorphic),
 m_ignore_labels (ignore_labels)
 {
   function *source_func = DECL_STRUCT_FUNCTION (source_func_decl);
@@ -156,23 +154,7 @@ func_checker::compare_decl (tree t1, tree t2)
   if (!compatible_types_p (TREE_TYPE (t1), TREE_TYPE (t2)))
 return return_false ();
 
-  /* TODO: we are actually too strict here.  We only need to compare if
- T1 can be used in polymorphic call.  */
-  if (TREE_ADDRESSABLE (t1)
-  && m_compare_polymorphic
-  && !compatible_polymorphic_types_p (TREE_TYPE (t1), TREE_TYPE (t2),
-	  false))
-return return_false ();
-
-  if ((t == VAR_DECL || t == PARM_DECL || t == RESULT_DECL)
-  && DECL_BY_REFERENCE (t1)
-  && m_compare_polymorphic
-  && !compatible_polymorphic_types_p (TREE_TYPE (t1), TREE_TYPE (t2),
-	  true))
-return return_false ();
-
   bool existed_p;
-
   tree  = m_decl_map.get_or_insert (t1, _p);
   if (existed_p)
 return return_with_debug (slot == t2);
diff --git a/gcc/ipa-icf-gimple.h b/gcc/ipa-icf-gimple.h
index b760b0fdce3..75f2f24ff4a 100644
--- a/gcc/ipa-icf-gimple.h
+++ b/gcc/ipa-icf-gimple.h
@@ -128,7 +128,6 @@ public:
  Similarly, IGNORE_SOURCE_DECLS and IGNORE_TARGET_DECLS are sets
  of declarations that can be skipped.  */
   func_checker (tree source_func_decl, tree target_func_decl,
-		bool compare_polymorphic,
 		bool ignore_labels = false,
 		hash_set *ignored_source_nodes = NULL,
 		hash_set *ignored_target_nodes = NULL);
@@ -258,9 +257,6 @@ private:
   /* Label to basic block index mapping.  */
   hash_map  m_label_bb_map;
 
-  /* Flag if polymorphic comparison should be executed.  */
-  bool m_compare_polymorphic;
-
   /* Flag if ignore labels in comparison.  */
   bool m_ignore_labels;
 
diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index 7cac480930b..f6400d48e27 100644
--- a/gcc/ipa-icf.c
+++ b/gcc/ipa-icf.c
@@ -845,7 +845,6 @@ sem_function::equals_private (sem_item *item)
 return return_false ();
 
   m_checker = new func_checker (decl, m_compared_func->decl,
-compare_polymorphic_p (),
 false,
 _set,
 _compared_func->refs_set);


[PATCH 2/9] operand_equal_p: add support for FIELD_DECL

2019-08-06 Thread Martin Liska

gcc/ChangeLog:

2019-07-24  Martin Liska  

* fold-const.c (operand_equal_p): Support FIELD_DECL
as well.
* tree.c (add_expr): Hast DECL_FIELD_OFFSET and
DECL_FIELD_BIT_OFFSET for FIELD_DECL.

gcc/testsuite/ChangeLog:

2019-07-24  Martin Liska  

* gcc.dg/vect/vect-35-big-array.c: Vectorize one more loop.
* gcc.dg/vect/vect-35.c: Likewise.
* gcc.dg/pr70740.c: Move from torture and set -O2.
* gfortran.dg/vect/vect-8.f90: Update scanned pattern.
---
 gcc/fold-const.c  | 34 ---
 gcc/testsuite/gcc.dg/{torture => }/pr70740.c  |  3 +-
 gcc/testsuite/gcc.dg/vect/vect-35-big-array.c |  3 +-
 gcc/testsuite/gcc.dg/vect/vect-35.c   |  3 +-
 gcc/testsuite/gfortran.dg/vect/vect-8.f90 |  2 +-
 gcc/tree.c|  4 +++
 6 files changed, 38 insertions(+), 11 deletions(-)
 rename gcc/testsuite/gcc.dg/{torture => }/pr70740.c (77%)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 0bd68b5e2d4..52414f7729e 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -3462,11 +3462,35 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
 	}
 
 case tcc_declaration:
-  /* Consider __builtin_sqrt equal to sqrt.  */
-  return (TREE_CODE (arg0) == FUNCTION_DECL
-	  && fndecl_built_in_p (arg0) && fndecl_built_in_p (arg1)
-	  && DECL_BUILT_IN_CLASS (arg0) == DECL_BUILT_IN_CLASS (arg1)
-	  && DECL_FUNCTION_CODE (arg0) == DECL_FUNCTION_CODE (arg1));
+  switch (TREE_CODE (arg0))
+	{
+	case FUNCTION_DECL:
+	  /* Consider __builtin_sqrt equal to sqrt.  */
+	  return (fndecl_built_in_p (arg0) && fndecl_built_in_p (arg1)
+		  && DECL_BUILT_IN_CLASS (arg0) == DECL_BUILT_IN_CLASS (arg1)
+		  && DECL_FUNCTION_CODE (arg0) == DECL_FUNCTION_CODE (arg1));
+	case FIELD_DECL:
+	  {
+	tree fo0 = DECL_FIELD_OFFSET (arg0);
+	tree fo1 = DECL_FIELD_OFFSET (arg1);
+	if (fo0 != NULL && fo1 != NULL
+		&& !operand_equal_p (fo0, fo1, OEP_ONLY_CONST))
+	  return false;
+	else if (fo0 != fo1)
+	  return false;
+
+	tree fbo0 = DECL_FIELD_BIT_OFFSET (arg0);
+	tree fbo1 = DECL_FIELD_BIT_OFFSET (arg1);
+	if (fbo0 != NULL && fbo1 != NULL
+		&& !operand_equal_p (fbo0, fbo1, OEP_ONLY_CONST))
+	  return false;
+	else if (fbo0 != fbo1)
+	  return false;
+	return true;
+	  }
+	default:
+	  return false;
+	}
 
 case tcc_exceptional:
   if (TREE_CODE (arg0) == CONSTRUCTOR)
diff --git a/gcc/testsuite/gcc.dg/torture/pr70740.c b/gcc/testsuite/gcc.dg/pr70740.c
similarity index 77%
rename from gcc/testsuite/gcc.dg/torture/pr70740.c
rename to gcc/testsuite/gcc.dg/pr70740.c
index 5bf8e4adc91..186da1b2637 100644
--- a/gcc/testsuite/gcc.dg/torture/pr70740.c
+++ b/gcc/testsuite/gcc.dg/pr70740.c
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-options "-O2" } */
 
 extern int foo (void);
 extern void *memcpy (void *, const void *, __SIZE_TYPE__);
@@ -32,7 +33,7 @@ baz ()
 e = c.a3;
   else
 e = c.a1;
-  memcpy (d.a, e, 6);
+  memcpy (d.a, e, 6); /* { dg-warning "reading 5 bytes from a region of size 0" } */
   f = bar ();
   memcpy (d.a, f, 1);
 }
diff --git a/gcc/testsuite/gcc.dg/vect/vect-35-big-array.c b/gcc/testsuite/gcc.dg/vect/vect-35-big-array.c
index ca57a10f714..fa356c2c4a2 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-35-big-array.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-35-big-array.c
@@ -47,5 +47,4 @@ int main (void)
 }
 
 
-/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect"  { xfail { ia64-*-* sparc*-*-* } } } } */
-/* { dg-final { scan-tree-dump "can't determine dependence between" "vect" } } */
+/* { dg-final { scan-tree-dump-times "vectorized 2 loops" 1 "vect"  { xfail { ia64-*-* sparc*-*-* } } } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-35.c b/gcc/testsuite/gcc.dg/vect/vect-35.c
index 76fe32d68ad..3023c8c714f 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-35.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-35.c
@@ -47,5 +47,4 @@ int main (void)
 } 
 
 
-/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect"  { xfail { ia64-*-* sparc*-*-* } } } } */
-/* { dg-final { scan-tree-dump "can't determine dependence between" "vect" } } */
+/* { dg-final { scan-tree-dump-times "vectorized 2 loops" 1 "vect"  { xfail { ia64-*-* sparc*-*-* } } } } */
diff --git a/gcc/testsuite/gfortran.dg/vect/vect-8.f90 b/gcc/testsuite/gfortran.dg/vect/vect-8.f90
index e26cdf95e51..f83f0d0aa27 100644
--- a/gcc/testsuite/gfortran.dg/vect/vect-8.f90
+++ b/gcc/testsuite/gfortran.dg/vect/vect-8.f90
@@ -704,5 +704,5 @@ CALL track('KERNEL  ')
 RETURN
 END SUBROUTINE kernel
 
-! { dg-final { scan-tree-dump-times "vectorized 22 loops" 1 "vect" { target vect_intdouble_cv

[PATCH 0/9] IPA ICF overhaul

2019-08-06 Thread Martin Liska
Hi.

It's some time I implemented first version of IPA ICF pass. Since that
I experienced more with the GCC internals and now is the right time
to do an overhaul.

Main motivation of changes is to share as many as possible in between
current operand_equal_p and ipa_icf::compare_operand. That's achieved
by a new class operand_compare. That allows use to share and unify
a lot of code. Apart from that I would like to learn current operand_equal_p
to handle new tree types.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests. I also
built Firefox, Godot engine.

Thanks,
Martin

Martin Liska (9):
  Replace int with boolean in predicate functions.
  operand_equal_p: add support for FIELD_DECL
  operand_equal_p: add support for OBJ_TYPE_REF.
  Strengthen alias_ptr_types_compatible_p in LTO mode.
  Come up with an abstraction.
  Integrate that for IPA ICF.
  IPA ICF: remove dead code
  Remove comparison for polymorphic types.
  Remove alias set comparison.

 gcc/alias.c   |   7 +-
 gcc/fold-const.c  | 547 +++---
 gcc/fold-const.h  |  30 +-
 gcc/ipa-icf-gimple.c  | 328 ++-
 gcc/ipa-icf-gimple.h  |  16 +-
 gcc/ipa-icf.c |  19 +-
 gcc/ipa-icf.h |   3 -
 .../c-c++-common/Wstringop-truncation-4.c |   2 +-
 gcc/testsuite/gcc.dg/ipa/ipa-icf-40.c |  32 +
 gcc/testsuite/gcc.dg/{torture => }/pr70740.c  |   3 +-
 gcc/testsuite/gcc.dg/tree-ssa/pr64910-2.c |   2 +-
 gcc/testsuite/gcc.dg/tree-ssa/pr79352.c   |   2 +-
 gcc/testsuite/gcc.dg/vect/vect-35-big-array.c |   3 +-
 gcc/testsuite/gcc.dg/vect/vect-35.c   |   3 +-
 gcc/testsuite/gfortran.dg/vect/vect-8.f90 |   2 +-
 gcc/tree.c| 273 -
 16 files changed, 588 insertions(+), 684 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/ipa-icf-40.c
 rename gcc/testsuite/gcc.dg/{torture => }/pr70740.c (77%)

-- 
2.22.0



[PATCH 4/9] Strengthen alias_ptr_types_compatible_p in LTO mode.

2019-08-06 Thread Martin Liska

gcc/ChangeLog:

2019-07-24  Martin Liska  

* alias.c (alias_ptr_types_compatible_p): Strengten
type comparison in LTO mode.
---
 gcc/alias.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/alias.c b/gcc/alias.c
index 2755df72907..bae4ddaebaf 100644
--- a/gcc/alias.c
+++ b/gcc/alias.c
@@ -793,8 +793,11 @@ alias_ptr_types_compatible_p (tree t1, tree t2)
   || ref_all_alias_ptr_type_p (t2))
 return false;
 
-  return (TYPE_MAIN_VARIANT (TREE_TYPE (t1))
-	  == TYPE_MAIN_VARIANT (TREE_TYPE (t2)));
+  if (in_lto_p)
+return get_alias_set (t1) == get_alias_set (t2);
+  else
+return (TYPE_MAIN_VARIANT (TREE_TYPE (t1))
+	== TYPE_MAIN_VARIANT (TREE_TYPE (t2)));
 }
 
 /* Create emptry alias set entry.  */


[PATCH 3/9] operand_equal_p: add support for OBJ_TYPE_REF.

2019-08-06 Thread Martin Liska

gcc/ChangeLog:

2019-07-24  Martin Liska  

* fold-const.c (operand_equal_p): Support OBJ_TYPE_REF.
* tree.c (add_expr): Hash parts of OBJ_TYPE_REF.
---
 gcc/fold-const.c | 21 +
 gcc/tree.c   |  9 +
 2 files changed, 30 insertions(+)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 52414f7729e..4bcde22ada7 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -3323,6 +3323,27 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
 	  flags &= ~OEP_ADDRESS_OF;
 	  return OP_SAME (1) && OP_SAME (2);
 
+	/* Virtual table call.  */
+	case OBJ_TYPE_REF:
+	  {
+	if (!operand_equal_p (OBJ_TYPE_REF_EXPR (arg0),
+  OBJ_TYPE_REF_EXPR (arg1), flags))
+	  return false;
+	if (virtual_method_call_p (arg0))
+	  {
+		if (tree_to_uhwi (OBJ_TYPE_REF_TOKEN (arg0))
+		!= tree_to_uhwi (OBJ_TYPE_REF_TOKEN (arg1)))
+		  return false;
+		if (!types_same_for_odr (obj_type_ref_class (arg0),
+	 obj_type_ref_class (arg1)))
+		  return false;
+		if (!operand_equal_p (OBJ_TYPE_REF_OBJECT (arg0),
+  OBJ_TYPE_REF_OBJECT (arg1), flags))
+		  return false;
+	  }
+	return true;
+	  }
+
 	default:
 	  return false;
 	}
diff --git a/gcc/tree.c b/gcc/tree.c
index 91ebc9eddc4..2207f644fed 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -8011,6 +8011,15 @@ add_expr (const_tree t, inchash::hash , unsigned int flags)
 	  inchash::add_expr (TARGET_EXPR_SLOT (t), hstate, flags);
 	  return;
 
+	/* Virtual table call.  */
+	case OBJ_TYPE_REF:
+	  inchash::add_expr (OBJ_TYPE_REF_EXPR (t), hstate, flags);
+	  if (virtual_method_call_p (t))
+		{
+		  inchash::add_expr (OBJ_TYPE_REF_TOKEN (t), hstate, flags);
+		  inchash::add_expr (OBJ_TYPE_REF_OBJECT (t), hstate, flags);
+		}
+	  return;
 	default:
 	  break;
 	}


[PATCH 0/4] Store multiple values for single value profilers

2019-06-04 Thread Martin Liska
Hi.

It's becoming more common that a training run happens in parallel environment.
That can lead to a not reproducible builds caused by different order of merging
of .gcda files. So that I'm suggesting to store up to 4 values for 
HIST_TYPE_SINGLE_VALUE
and HIST_TYPE_INDIR_CALL on disk. If the capacity is exceeded the whole counter 
is
marked as unstable (not reproducible).

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

marxin (4):
  Remove indirect call top N counter type.
  Implement N disk counters for single value and indirect call counters.
  Dump histograms only if present.
  Update a bit dump format.

 gcc/doc/invoke.texi   |   3 -
 gcc/gcov-counter.def  |   3 -
 gcc/gcov-io.h |   9 +-
 gcc/ipa-profile.c |  13 ++-
 gcc/params.def|   8 --
 gcc/profile.c |   1 -
 gcc/tree-profile.c|  23 +---
 gcc/value-prof.c  | 224 --
 gcc/value-prof.h  |   4 +-
 libgcc/Makefile.in|  10 +-
 libgcc/libgcov-driver.c   |  80 --
 libgcc/libgcov-merge.c| 139 +--
 libgcc/libgcov-profiler.c | 176 ++
 libgcc/libgcov-util.c |  19 
 libgcc/libgcov.h  |  12 +-
 15 files changed, 179 insertions(+), 545 deletions(-)

-- 
2.21.0