Re: [PATCH V6 11/11] bpf: add myself as the maintainer for the eBPF port

2019-09-08 Thread Gerald Pfeifer
On Thu, 29 Aug 2019, Jose E. Marchesi wrote:
> ChangeLog:
> 
>   * MAINTAINERS: Add myself as the maintainer of the eBPF port.
>   Remove myself from Write After Approval section.

Approved.

As in: Approved by the steering committed assuming the patchset passes
technical review. :-)

Thanks for working on this, Joe, and congrats to the new hat!

Gerald


Re: [PATCH] Optimize to_chars

2019-09-08 Thread Antony Polukhin
We've already beaten this topic to death, so let's put a final nail in
the coffin:


__to_chars_10_impl is quite fast. According to the IACA the main loop
takes only 6.0 cycles, the whole function with one iteration takes
10.0 cycles. Replacing the __first[pos] and __first[pos - 1] with
__first[0] and __first[1] drops the function time to 7.53 cycles.

Changelog:

2019-09-08  Antony Polukhin  

* include/bits/charconv.h (__detail::__to_chars_10_impl): Replace
final offsets with constants.


And that's the only optimization that improves all the usecases and
reduces code size on 3 instructions.

Different approaches for optimizing the loop were showing different
results depending on the workload. The most interesting result gives
the compressed table of binary coded decimals:

static constexpr unsigned char __binary_coded_decimals[50] =
{ 0x00, 0x02, 0x04, 0x06, 0x08,  0x10... 0x98 };
unsigned __pos = __len - 1;
while (__val >= 100)
{
  auto const addition = __val & 1;
  auto const __num = (__val % 100) >> 1;
  __val /= 100;
  auto const __bcd = __binary_coded_decimals[__num];
  __first[__pos] = '0' + (__bcd & 0xf) + addition;
  __first[__pos - 1] = '0' + (__bcd >> 4);
  __pos -= 2;
}

That approach shows the same results or even outperforms the existing
approach with __digits[201] = "0001020304..." in case of cold cache.
It also produces slightly smaller binaries. Unfortunately on a warmed
up cache it's slower than the existing approach. I don't think that
it's a worth change.

Attaching some of the benchmarks as a separate file (not for merge,
just something to experiment with).


-- 
Best regards,
Antony Polukhin
diff --git a/libstdc++-v3/include/bits/charconv.h 
b/libstdc++-v3/include/bits/charconv.h
index 0911660..a5b6be5 100644
--- a/libstdc++-v3/include/bits/charconv.h
+++ b/libstdc++-v3/include/bits/charconv.h
@@ -92,11 +92,11 @@ namespace __detail
   if (__val >= 10)
{
  auto const __num = __val * 2;
- __first[__pos] = __digits[__num + 1];
- __first[__pos - 1] = __digits[__num];
+ __first[1] = __digits[__num + 1];
+ __first[0] = __digits[__num];
}
   else
-   __first[__pos] = '0' + __val;
+   __first[0] = '0' + __val;
 }
 
 } // namespace __detail
#include 
#include 
#include 


// Adjust those variables to test on different workloads
constexpr unsigned From = 13;
constexpr unsigned To   = 130004;
constexpr unsigned Len  = 6;
// Bytes of CPU cache to reset
#define RANGES ->Args({16 * 1024 * 1024})



namespace std { namespace __detail {
  template
int
__to_chars_10_table_2_impl(char* __first, unsigned __len, _Tp __val) noexcept
{
  static_assert(is_integral<_Tp>::value, "implementation bug");
  static_assert(is_unsigned<_Tp>::value, "implementation bug");

  static constexpr char __digits[201] =
"0001020304050607080910111213141516171819"
"2021222324252627282930313233343536373839"
"4041424344454647484950515253545556575859"
"6061626364656667686970717273747576777879"
"8081828384858687888990919293949596979899";
  unsigned __pos = __len - 1;
  while (__val >= 100)
{
  auto const __num = (__val % 100) * 2;
  __val /= 100;
  __first[__pos] = __digits[__num + 1];
  __first[__pos - 1] = __digits[__num];
  __pos -= 2;
}
  if (__val >= 10)
{
  auto const __num = __val * 2;
  __first[1] = __digits[__num + 1];
  __first[0] = __digits[__num];
}
  else
__first[0] = '0' + __val;
return 0;
}

  template
int
__to_chars_10_bcd_impl(char* __first, unsigned __len, _Tp __val) noexcept
{
  static_assert(is_integral<_Tp>::value, "implementation bug");
  static_assert(is_unsigned<_Tp>::value, "implementation bug");

  static constexpr unsigned char __binary_coded_decimals[100] =
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10
  , 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20
  , 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30
  , 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40
  , 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x50
  , 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x60
  , 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70
  , 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x80
  , 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x90
  , 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99};
  unsigned __pos = __len - 1;
  while (__val >= 100)
{
  auto const __num = __val % 100;
  __val /= 100;
auto const __bcd = __binary_coded_decimals[__num];
  __first[__pos] = '0' + (__bcd & 0xf);
  __first[__pos - 1] = '0' + (__bcd >> 4);
  __pos -= 2;
}
  if (__val >= 10)
{
auto const __bcd = __binary_coded_decimals[__val];
  __first[1] = '0' + (__bcd & 0xf);
  __first[0] = '0' + (__bcd >> 4);
}
  else
__first[0] = '0' + __

Re: [PATCH v2 4/6] compiler-gcc.h: add asm_inline definition

2019-09-08 Thread Miguel Ojeda
On Sat, Sep 7, 2019 at 3:11 PM Segher Boessenkool
 wrote:
>
> I wouldn't.  Please stop using that straw man.  I'm not saying version
> checks are good, or useful for most things.  I am saying they are not.
>
> Predefined compiler symbols to do version checking (of a feature) is
> just a lesser instance of the same problem though.  (And it causes its
> own more or less obvious problems as well).

That is fair enough, but what are you suggesting we use, then?

Because "testing to do X to know if you can do X" cannot work with
source code alone and implies each project has to redo this work in
its build system for each compiler, plus each project ends up with
different names for these macros. The C++20 approach of having
standardized macros for major features is way better (whether we have
one macro per feature or a __has_feature(X) macro). Note this does not
mean we need to take this to the extreme and have a feature-test macro
for *every* feature, bugfix or behavior change as a macro.

Cheers,
Miguel


[PATCH, libstdc++] Improve the performance of std::uniform_int_distribution (fewer divisions)

2019-09-08 Thread Daniel Lemire
Even on recent processors, integer division is relatively expensive.
The current implementation of  std::uniform_int_distribution typically
requires two divisions by invocation:

// downscaling
const __uctype __uerange = __urange + 1; // __urange can be zero
const __uctype __scaling = __urngrange / __uerange;
const __uctype __past = __uerange * __scaling;
do
  __ret = __uctype(__urng()) - __urngmin;
while (__ret >= __past);
__ret /= __scaling;

We can achieve the same algorithmic result with at most one division,
and typically
no division at all without requiring more calls to the random number generator.
This was recently added to Swift (https://github.com/apple/swift/pull/25286)

The main challenge is that we need to be able to compute the "full"
product. E.g.,
given two 64-bit integers, we want the 128-bit result; given two 32-bit integers
we want the 64-bit result. This is fast on common processors. The
128-bit product
is not natively supported in C/C++ but can be achieved with the
__uint128_t extension
which is widely supported by GCC. The patch checks for __uint128_t support; when
support is lacking, we fallback on the existing approach.

For example, if we replace the above code by the following, we get a substantial
performance boost on skylake microarchitectures. E.g., it can
be twice as fast to shuffle arrays of 1 million elements (e.g., using
the following
benchmark: https://github.com/lemire/simple_cpp_shuffle_benchmark )


  const __uctype __uerange = __urange + 1; // __urange can be zero
  uint64_t __product = (__uctype(__urng()) - __urngmin) * __uerange;
  uint32_t __lsb = uint32_t(__product);
  if(__lsb < __uerange) {
uint64_t __threshold = -__uerange % __uerange;
while (__lsb < __threshold) {
  __product = (__uctype(__urng()) - __urngmin) * __uerange;
  __lsb = uint32_t(__product);
}
  }

Included is a patch that would bring better performance (e.g., 2x gain) to
std::uniform_int_distribution  in some cases.

This patch proposal was previously submitted solely to the libc++ list
and improved following feedback by Jonathan Wakely.

Reference: Fast Random Integer Generation in an Interval, ACM Transactions on
Modeling and Computer Simulation 29 (1), 2019 https://arxiv.org/abs/1805.10941
Index: trunk/libstdc++-v3/include/bits/uniform_int_dist.h
===
--- trunk/libstdc++-v3/include/bits/uniform_int_dist.h  (revision 275324)
+++ trunk/libstdc++-v3/include/bits/uniform_int_dist.h  (working copy)
@@ -33,6 +33,7 @@

 #include 
 #include 
+#include 

 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -242,15 +243,59 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION

if (__urngrange > __urange)
  {
-   // downscaling
-   const __uctype __uerange = __urange + 1; // __urange can be zero
-   const __uctype __scaling = __urngrange / __uerange;
-   const __uctype __past = __uerange * __scaling;
-   do
- __ret = __uctype(__urng()) - __urngmin;
-   while (__ret >= __past);
-   __ret /= __scaling;
- }
+   const __uctype __uerange = __urange + 1; // __urange can be zero
+#if _GLIBCXX_USE_INT128 == 1
+if(sizeof(__uctype) == sizeof(uint64_t) and
+  (__urngrange == numeric_limits::max()))
+{
+  // 64-bit case
+  // reference: Fast Random Integer Generation in an Interval
+  // ACM Transactions on Modeling and Computer Simulation 29 (1), 2019
+  // https://arxiv.org/abs/1805.10941
+  __uint128_t __product = (__uctype(__urng()) - __urngmin) * __uerange;
+  uint64_t __lsb = uint64_t(__product);
+  if(__lsb < __uerange)
+  {
+uint64_t __threshold = -__uerange % __uerange;
+while (__lsb < __threshold)
+{
+  __product = (__uctype(__urng()) - __urngmin) * __uerange;
+  __lsb = uint64_t(__product);
+}
+  }
+  __ret = __product >> 64;
+}
+else
+#endif // _GLIBCXX_USE_INT128 == 1
+if(sizeof(__uctype) == sizeof(uint32_t)
+  and (__urngrange == numeric_limits::max()) )
+{
+  // 32-bit case
+  // reference: Fast Random Integer Generation in an Interval
+  // ACM Transactions on Modeling and Computer Simulation 29 (1), 2019
+  // https://arxiv.org/abs/1805.10941
+  uint64_t __product = (__uctype(__urng()) - __urngmin) * __uerange;
+  uint32_t __lsb = uint32_t(__product);
+  if(__lsb < __uerange) {
+uint64_t __threshold = -__uerange % __uerange;
+while (__lsb < __threshold) {
+  __product = (__uctype(__urng()) - __urngmin) * __uerange;
+  __lsb = uint32_t(__product);
+}
+  }
+  __ret = __product >> 32;
+}
+else
+{
+  // fallback case (2 divisions)
+  const __uctype __scaling = __urngrange / __uerange;
+  const __uctype __past = __uerange * _

Re: [PATCH V6 11/11] bpf: add myself as the maintainer for the eBPF port

2019-09-08 Thread Jose E. Marchesi


> ChangeLog:
> 
>   * MAINTAINERS: Add myself as the maintainer of the eBPF port.
>   Remove myself from Write After Approval section.

Approved.

As in: Approved by the steering committed assuming the patchset passes
technical review. :-)

Thanks for working on this, Joe, and congrats to the new hat!

Thank you! :)


C++ PATCH for c++/84374 - diagnose invalid uses of decltype(auto)

2019-09-08 Thread Marek Polacek
[dcl.type.auto.deduct]/5 "If the placeholder-type-specifier is of the
form type-constraintopt decltype(auto), T shall be the placeholder alone."

So, only plain decltype(auto) is allowed.  But we aren't diagnosing it in
function declarations, because do_auto_deduction is never called for those.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2019-09-08  Marek Polacek  

PR c++/84374 - diagnose invalid uses of decltype(auto).
* decl.c (grokdeclarator): Diagnose wrong usage of decltype(auto) in
a function declaration.

* g++.dg/cpp1y/auto-fn57.C: New test.

diff --git gcc/cp/decl.c gcc/cp/decl.c
index 88e2c3beb2b..b130934 100644
--- gcc/cp/decl.c
+++ gcc/cp/decl.c
@@ -11560,6 +11560,14 @@ grokdeclarator (const cp_declarator *declarator,
  "cannot have deduced return type");
virtualp = false;
  }
+   else if (is_auto (auto_node)
+&& AUTO_IS_DECLTYPE (auto_node)
+&& type != auto_node)
+ {
+   error_at (typespec_loc, "%qT as type rather than "
+ "plain %", type);
+   return error_mark_node;
+ }
  }
else if (!is_auto (type) && sfk != sfk_conversion)
  {
@@ -11580,6 +11588,16 @@ grokdeclarator (const cp_declarator *declarator,
"invalid use of %");
return error_mark_node;
  }
+   else if (tree a = type_uses_auto (late_return_type))
+ {
+   if (AUTO_IS_DECLTYPE (a) && a != late_return_type)
+ {
+   error_at (typespec_loc, "%qT as type rather than "
+ "plain %",
+ late_return_type);
+   return error_mark_node;
+ }
+ }
tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node);
if (!tmpl)
  if (tree late_auto = type_uses_auto (late_return_type))
diff --git gcc/testsuite/g++.dg/cpp1y/auto-fn57.C 
gcc/testsuite/g++.dg/cpp1y/auto-fn57.C
new file mode 100644
index 000..e58df187df5
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp1y/auto-fn57.C
@@ -0,0 +1,18 @@
+// PR c++/84374 - diagnose invalid uses of decltype(auto).
+// { dg-do compile { target c++14 } }
+
+auto l = [](auto* r)->decltype(auto)* { return r; }; // { dg-error "as type 
rather than plain" }
+auto m = [](auto* r)->decltype(auto)& { return *r; }; // { dg-error "as type 
rather than plain" }
+
+decltype(auto)* f(); // { dg-error "as type rather than plain" }
+decltype(auto)& f2(); // { dg-error "as type rather than plain" }
+decltype(auto)* f3() { return 42; } // { dg-error "as type rather than plain" }
+decltype(auto)& f4() { return 42; } // { dg-error "as type rather than plain" }
+
+
+class C {
+  decltype(auto)* g(); // { dg-error "as type rather than plain" }
+  decltype(auto)& g2(); // { dg-error "as type rather than plain" }
+  decltype(auto)* g3() { } // { dg-error "as type rather than plain" }
+  decltype(auto)& g4() { } // { dg-error "as type rather than plain" }
+};


Re: [PATCH] genemit: Print file+line in the "Splitting with" message

2019-09-08 Thread Jeff Law
On 9/6/19 1:25 PM, Segher Boessenkool wrote:
> It's tiresome to have to look in insn-emit.c to see where some split
> came from, so let's print that info to the dump file as well.  But
> don't print the full path, just the basename, for greater readability.
> 
> Testing on powerpc64-linux {-m32,-m64}.  Is this okay for trunk if that
> succeeds?
> 
> 
> Segher
> 
> 
> 2019-09-06  Segher Boessenkool  
> 
>   * genemit.c (gen_split): Print the filename and line number where the
>   splitter (or peephole2) was defined, to the dump file.
OK
jeff


[PATCH,RFC,V5 1/6] Add new function lang_GNU_GIMPLE

2019-09-08 Thread Indu Bhagat
gcc/ChangeLog:

* langhooks.c (lang_GNU_GIMPLE): New Function.
* langhooks.h: New Prototype.

---
 gcc/ChangeLog   | 5 +
 gcc/langhooks.c | 9 +
 gcc/langhooks.h | 1 +
 3 files changed, 15 insertions(+)

diff --git a/gcc/langhooks.c b/gcc/langhooks.c
index 89fb5bc..66daa9a 100644
--- a/gcc/langhooks.c
+++ b/gcc/langhooks.c
@@ -821,3 +821,12 @@ lang_GNU_OBJC (void)
 {
   return strncmp (lang_hooks.name, "GNU Objective-C", 15) == 0;
 }
+
+/* Returns true if the current lang_hooks represents the GNU GIMPLE
+   frontend.  */
+
+bool
+lang_GNU_GIMPLE (void)
+{
+  return strncmp (lang_hooks.name, "GNU GIMPLE", 10) == 0;
+}
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index a45579b..0ac794e 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -570,5 +570,6 @@ extern bool lang_GNU_C (void);
 extern bool lang_GNU_CXX (void);
 extern bool lang_GNU_Fortran (void);
 extern bool lang_GNU_OBJC (void);
+extern bool lang_GNU_GIMPLE (void);
 
 #endif /* GCC_LANG_HOOKS_H */
-- 
1.8.3.1



[PATCH,RFC,V5 3/6] Setup for CTF generation and emission

2019-09-08 Thread Indu Bhagat
Initialize CTF container when -gtLEVEL is specified.  Generate CTF debug info
for global decls.  Import the CTF header from binutils.

gcc/ChangeLog:
 
* Makefile.in: Add ctfout.* files to GTFILES.
* cgraphunit.c (symbol_table::finalize_compilation_unit): Generate CTF
debug info for decl. Invoke CTF debug info emission.
* ctfout.c: New file.
* ctfout.h: Likewise.
* gengtype.c (open_base_files): Add ctfout.h to ifiles.
* passes.c (rest_of_decl_compilation): Generate CTF debug info for
decl.
* toplev.c (process_options): Inform the user and ignore -gtLEVEL if
frontend is not C.
(toplev::finalize): Finalize CTF containers.

gcc/testsuite/ChangeLog:

* gcc.dg/debug/ctf/ctf-1.c: New test.
* gcc.dg/debug/ctf/ctf-preamble-1.c: Likewise.
* gcc.dg/debug/ctf/ctf.exp: Add CTF testsuite.
* gcc.dg/debug/dwarf2-ctf-1.c: New test.

include/ChangeLog:

* ctf.h: Import from binutils.

---
 gcc/ChangeLog   |  14 +
 gcc/Makefile.in |   3 +
 gcc/cgraphunit.c|  12 +-
 gcc/ctfout.c| 175 +
 gcc/ctfout.h|  53 +++
 gcc/gengtype.c  |   4 +-
 gcc/passes.c|   7 +-
 gcc/testsuite/ChangeLog |   7 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-1.c  |   6 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-preamble-1.c |  11 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf.exp  |  41 ++
 gcc/testsuite/gcc.dg/debug/dwarf2-ctf-1.c   |   7 +
 gcc/toplev.c|  18 +
 include/ChangeLog   |   4 +
 include/ctf.h   | 483 
 15 files changed, 839 insertions(+), 6 deletions(-)
 create mode 100644 gcc/ctfout.c
 create mode 100644 gcc/ctfout.h
 create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-1.c
 create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-preamble-1.c
 create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf.exp
 create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2-ctf-1.c
 create mode 100644 include/ctf.h

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 99d88a4..62d9256 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1256,6 +1256,7 @@ OBJS = \
cfgloopanal.o \
cfgloopmanip.o \
cfgrtl.o \
+   ctfout.o \
symtab.o \
cgraph.o \
cgraphbuild.o \
@@ -2534,6 +2535,8 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h 
$(srcdir)/coretypes.h \
   $(srcdir)/dwarf2asm.c \
   $(srcdir)/dwarf2cfi.c \
   $(srcdir)/dwarf2out.c \
+  $(srcdir)/ctfout.h \
+  $(srcdir)/ctfout.c \
   $(srcdir)/tree-vect-generic.c \
   $(srcdir)/dojump.c $(srcdir)/emit-rtl.h \
   $(srcdir)/emit-rtl.c $(srcdir)/except.h $(srcdir)/explow.c $(srcdir)/expr.c \
diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index cb08efe..e8130a1 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -205,6 +205,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "lto-section-names.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "ctfout.h"
 
 /* Queue of cgraph nodes scheduled to be added into cgraph.  This is a
secondary queue used during optimization to accommodate passes that
@@ -2851,17 +2852,22 @@ symbol_table::finalize_compilation_unit (void)
 
   if (!seen_error ())
 {
-  /* Emit early debug for reachable functions, and by consequence,
-locally scoped symbols.  */
+  /* Emit early debug and CTF debug info for reachable functions, and by
+consequence, locally scoped symbols.  */
   struct cgraph_node *cnode;
   FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (cnode)
-   (*debug_hooks->early_global_decl) (cnode->decl);
+   {
+ (*debug_hooks->early_global_decl) (cnode->decl);
+ ctf_early_global_decl (cnode->decl);
+   }
 
   /* Clean up anything that needs cleaning up after initial debug
 generation.  */
   debuginfo_early_start ();
   (*debug_hooks->early_finish) (main_input_filename);
+  ctf_early_finish (main_input_filename);
   debuginfo_early_stop ();
+
 }
 
   /* Finally drive the pass manager.  */
diff --git a/gcc/ctfout.c b/gcc/ctfout.c
new file mode 100644
index 000..471cf80
--- /dev/null
+++ b/gcc/ctfout.c
@@ -0,0 +1,175 @@
+/* Output CTF format from GCC.
+   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 PUR

[PATCH,RFC,V5 2/6] Add CTF command line options : -gtLEVEL

2019-09-08 Thread Indu Bhagat
-gtLEVEL is used to request CTF debug information and also to specify how much
CTF debug information.

gcc/ChangeLog:
 
* common.opt: Add CTF debug info options.
* doc/invoke.texi: Document the CTF debug info options.
* flag-types.h (enum ctf_debug_info_levels): New enum.
* opts.c (common_handle_option): New Function.
(set_ctf_debug_level): Handle the new CTF debug info options.

---
 gcc/ChangeLog   |  8 
 gcc/common.opt  |  9 +
 gcc/doc/invoke.texi | 16 
 gcc/flag-types.h| 13 +
 gcc/opts.c  | 26 ++
 5 files changed, 72 insertions(+)

diff --git a/gcc/common.opt b/gcc/common.opt
index f2214ed..283a959 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -125,6 +125,11 @@ enum debug_info_levels debug_info_level = DINFO_LEVEL_NONE
 Variable
 bool use_gnu_debug_info_extensions
 
+; Level of CTF debugging information we are producing.  See flag-types.h
+; for the definitions of the different possible levels.
+Variable
+enum ctf_debug_info_levels ctf_debug_info_level = CTFINFO_LEVEL_NONE
+
 ; Original value of maximum field alignment in bytes, specified via
 ; -fpack-struct=.
 Variable
@@ -3011,6 +3016,10 @@ gcolumn-info
 Common Driver Var(debug_column_info,1) Init(1)
 Record DW_AT_decl_column and DW_AT_call_column in DWARF.
 
+gt
+Common Driver RejectNegative JoinedOrMissing
+Generate CTF debug information at default level.
+
 gdwarf
 Common Driver JoinedOrMissing Negative(gdwarf-)
 Generate debug information in default version of DWARF format.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index bfcd76e..af42da9 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -378,6 +378,7 @@ Objective-C and Objective-C++ Dialects}.
 @item Debugging Options
 @xref{Debugging Options,,Options for Debugging Your Program}.
 @gccoptlist{-g  -g@var{level}  -gdwarf  -gdwarf-@var{version} @gol
+-gt  -gt@var{level} @gol
 -ggdb  -grecord-gcc-switches  -gno-record-gcc-switches @gol
 -gstabs  -gstabs+  -gstrict-dwarf  -gno-strict-dwarf @gol
 -gas-loc-support  -gno-as-loc-support @gol
@@ -7823,6 +7824,21 @@ other DWARF-related options such as
 @option{-fno-dwarf2-cfi-asm}) retain a reference to DWARF Version 2
 in their names, but apply to all currently-supported versions of DWARF.
 
+@item -gt
+@itemx -gt@var{level}
+@opindex gt
+Request CTF debug information and use level to specify how much CTF debug
+information should be produced.  If -gt is specified without a value for level,
+the default level of CTF debug information is 2.
+
+Level 0 produces no CTF debug information at all.  Thus, -gt0 negates -gt.
+
+Level 1 produces CTF information for tracebacks only.  This includes callsite
+information, but does not include type information.
+
+Level 2 produces type information for entities (functions, data objects etc.)
+at file-scope or global-scope only.
+
 @item -gstabs
 @opindex gstabs
 Produce debugging information in stabs format (if that is supported),
diff --git a/gcc/flag-types.h b/gcc/flag-types.h
index a210328..61a1432 100644
--- a/gcc/flag-types.h
+++ b/gcc/flag-types.h
@@ -105,6 +105,19 @@ enum dwarf_gnat_encodings
   Emit GNAT encodings for the rest.  */
 };
 
+/* CTF debug info levels.
+   CTF debug info levels are untied with DWARF debug info levels because CTF
+   may co-exist with DWARF.  */
+enum ctf_debug_info_levels
+{
+  CTFINFO_LEVEL_NONE = 0, /* Write no CTF debug info.  */
+  CTFINFO_LEVEL_TERSE = 1,/* Write CTF information to support tracebacks
+only.  Not Implemented.  */
+  CTFINFO_LEVEL_NORMAL = 2/* Write CTF type information for all entities
+(functions, data objects, variables etc.)
+at file-scope or global-scope only.  */
+};
+
 /* Enumerate Objective-c instance variable visibility settings. */
 
 enum ivar_visibility
diff --git a/gcc/opts.c b/gcc/opts.c
index 07f701c..db3711c 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -196,6 +196,8 @@ static void set_debug_level (enum debug_info_type type, int 
extended,
 const char *arg, struct gcc_options *opts,
 struct gcc_options *opts_set,
 location_t loc);
+static void set_ctf_debug_level (const char *arg,
+struct gcc_options *opts, location_t loc);
 static void set_fast_math_flags (struct gcc_options *opts, int set);
 static void decode_d_option (const char *arg, struct gcc_options *opts,
 location_t loc, diagnostic_context *dc);
@@ -2759,6 +2761,10 @@ common_handle_option (struct gcc_options *opts,
   opts->x_flag_stack_usage_info = value != 0;
   break;
 
+case OPT_gt:
+  set_ctf_debug_level (arg, opts, loc);
+  break;
+
 case OPT_g:
   set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg, opts, opts_set,

[PATCH,RFC,V5 0/6] Support for CTF in GCC

2019-09-08 Thread Indu Bhagat
Hello,

This patch series adds support for CTF generation in GCC.

[Changes from V4]

1. Patch 4 brings in a number of bug fixes and enhancements. Few of them are:
   - Use DECL_UID () instead of htab_hash_pointer () for _DECL
   - Handle boolean and zero-sized bitfields
   - Do not inform () when skipping types.  Arguably this was intended for the
 GCC developer and not for the end user.
   - Other bugfixes around de-dupilication at the time of CTF Array or CTF
 function generation.

2. Patch 5 has added testcases.

3. Patch 6 is a new patch added for handling CTF section when LTO is enabled.

Work on CTF spec document is also in progress; will share something very soon.
In the interim, https://sourceware.org/ml/binutils/2019-04/msg00277.html may be
helpful.

For more context, please also see previous posting
https://gcc.gnu.org/ml/gcc-patches/2019-07/msg01209.html

NickA recently posted a changeset to the binutils mailing list that adds initial
support for linking CTF sections. Please see
https://sourceware.org/ml/binutils/2019-09/msg00045.html

( This current GCC  patch set has the ctf.h in sync with the above-mentioned
   binutils patch set. )

I will be connecting online to talk about the CTF support in GNU toolchain at
Cauldron 2019.  Posting these patches so that there is added context.

Testing :
Apart from the usual bootstrap and regression testing on x86_64/linux,
sparc64/linux, I have now compiled more codebases with -gt.

Thanks

Indu Bhagat (6):
  Add new function lang_GNU_GIMPLE
  Add CTF command line options : -gtLEVEL
  Setup for CTF generation and emission
  CTF generation for a single compilation unit
  Update CTF testsuite
  Handle CTF sections when LTO is enabled

 gcc/ChangeLog  |   97 +
 gcc/Makefile.in|5 +
 gcc/cgraphunit.c   |   12 +-
 gcc/common.opt |9 +
 gcc/ctfcreate.c|  557 ++
 gcc/ctfout.c   | 1941 
 gcc/ctfout.h   |  364 
 gcc/ctfutils.c |  198 ++
 gcc/doc/invoke.texi|   16 +
 gcc/flag-types.h   |   13 +
 gcc/gengtype.c |4 +-
 gcc/langhooks.c|9 +
 gcc/langhooks.h|1 +
 gcc/opts.c |   26 +
 gcc/passes.c   |7 +-
 gcc/testsuite/ChangeLog|   46 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-1.c |6 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-2.c |   10 +
 .../gcc.dg/debug/ctf/ctf-anonymous-struct-1.c  |   23 +
 .../gcc.dg/debug/ctf/ctf-anonymous-union-1.c   |   26 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-1.c   |   31 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c   |   39 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-1.c   |   30 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-2.c   |   39 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-3.c   |   16 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-4.c   |   22 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-complex-1.c |   22 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-1.c   |   44 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-2.c   |   30 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-3.c   |   41 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-4.c   |   21 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-1.c|   21 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-2.c|   26 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-float-1.c   |   16 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-1.c |   36 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-2.c |   16 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-3.c |   21 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-func-index-1.c  |   25 +
 .../gcc.dg/debug/ctf/ctf-function-pointers-1.c |   24 +
 .../gcc.dg/debug/ctf/ctf-function-pointers-2.c |   18 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-functions-1.c   |   34 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-int-1.c |   17 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-objt-index-1.c  |   29 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-pointers-1.c|   26 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-preamble-1.c|   11 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-1.c  |   33 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-str-table-1.c   |   26 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-1.c  |   25 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-2.c  |   30 +
 .../gcc.dg/debug/ctf/ctf-struct-array-1.c  |   36 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-1.c |   23 +
 .../gcc.dg/debug/ctf/ctf-typedef-struct-1.c|   12 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-union-1.c   |   14 +
 gcc/testsuite

[PATCH,RFC,V5 5/6] Update CTF testsuite

2019-09-08 Thread Indu Bhagat
[Changes from V4]
Added new testcases
 - gcc.dg/debug/ctf/ctf-bitfields-3.c
 - gcc.dg/debug/ctf/ctf-bitfields-4.c
 - gcc.dg/debug/ctf/ctf-cvr-quals-4.c
 - gcc.dg/debug/ctf/ctf-forward-3.c
 - gcc.dg/debug/ctf/ctf-function-pointers-2.c

gcc/testsuite/ChangeLog:

* gcc.dg/debug/ctf/ctf-2.c: New test.
* gcc.dg/debug/ctf/ctf-anonymous-struct-1.c: New test.
* gcc.dg/debug/ctf/ctf-anonymous-union-1.c: New test.
* gcc.dg/debug/ctf/ctf-array-1.c: New test.
* gcc.dg/debug/ctf/ctf-array-2.c: New test.
* gcc.dg/debug/ctf/ctf-bitfields-1.c: New test.
* gcc.dg/debug/ctf/ctf-bitfields-2.c: New test.
* gcc.dg/debug/ctf/ctf-bitfields-3.c: New test.
* gcc.dg/debug/ctf/ctf-bitfields-4.c: New test.
* gcc.dg/debug/ctf/ctf-complex-1.c: New test.
* gcc.dg/debug/ctf/ctf-cvr-quals-1.c: New test.
* gcc.dg/debug/ctf/ctf-cvr-quals-2.c: New test.
* gcc.dg/debug/ctf/ctf-cvr-quals-3.c: New test.
* gcc.dg/debug/ctf/ctf-cvr-quals-4.c: New test.
* gcc.dg/debug/ctf/ctf-enum-1.c: New test.
* gcc.dg/debug/ctf/ctf-enum-2.c: New test.
* gcc.dg/debug/ctf/ctf-float-1.c: New test.
* gcc.dg/debug/ctf/ctf-forward-1.c: New test.
* gcc.dg/debug/ctf/ctf-forward-2.c: New test.
* gcc.dg/debug/ctf/ctf-forward-3.c: New test.
* gcc.dg/debug/ctf/ctf-func-index-1.c: New test.
* gcc.dg/debug/ctf/ctf-function-pointers-1.c: New test.
* gcc.dg/debug/ctf/ctf-function-pointers-2.c: New test.
* gcc.dg/debug/ctf/ctf-functions-1.c: New test.
* gcc.dg/debug/ctf/ctf-int-1.c: New test.
* gcc.dg/debug/ctf/ctf-objt-index-1.c: New test.
* gcc.dg/debug/ctf/ctf-pointers-1.c: New test.
* gcc.dg/debug/ctf/ctf-skip-types-1.c: New test.
* gcc.dg/debug/ctf/ctf-str-table-1.c: New test.
* gcc.dg/debug/ctf/ctf-struct-1.c: New test.
* gcc.dg/debug/ctf/ctf-struct-2.c: New test.
* gcc.dg/debug/ctf/ctf-struct-array-1.c: New test.
* gcc.dg/debug/ctf/ctf-typedef-1.c: New test.
* gcc.dg/debug/ctf/ctf-typedef-struct-1.c: New test.
* gcc.dg/debug/ctf/ctf-union-1.c: New test.
* gcc.dg/debug/ctf/ctf-variables-1.c: New test.

---
 gcc/testsuite/ChangeLog| 39 +++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-2.c | 10 +
 .../gcc.dg/debug/ctf/ctf-anonymous-struct-1.c  | 23 +++
 .../gcc.dg/debug/ctf/ctf-anonymous-union-1.c   | 26 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-1.c   | 31 +++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-array-2.c   | 39 +++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-1.c   | 30 +++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-2.c   | 39 +++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-3.c   | 16 
 gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-4.c   | 22 +++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-complex-1.c | 22 +++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-1.c   | 44 ++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-2.c   | 30 +++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-3.c   | 41 
 gcc/testsuite/gcc.dg/debug/ctf/ctf-cvr-quals-4.c   | 21 +++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-1.c| 21 +++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-enum-2.c| 26 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-float-1.c   | 16 
 gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-1.c | 36 ++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-2.c | 16 
 gcc/testsuite/gcc.dg/debug/ctf/ctf-forward-3.c | 21 +++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-func-index-1.c  | 25 
 .../gcc.dg/debug/ctf/ctf-function-pointers-1.c | 24 
 .../gcc.dg/debug/ctf/ctf-function-pointers-2.c | 18 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-functions-1.c   | 34 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-int-1.c | 17 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-objt-index-1.c  | 29 ++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-pointers-1.c| 26 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-skip-types-1.c  | 33 
 gcc/testsuite/gcc.dg/debug/ctf/ctf-str-table-1.c   | 26 +
 gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-1.c  | 25 
 gcc/testsuite/gcc.dg/debug/ctf/ctf-struct-2.c  | 30 +++
 .../gcc.dg/debug/ctf/ctf-struct-array-1.c  | 36 ++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-typedef-1.c | 23 +++
 .../gcc.dg/debug/ctf/ctf-typedef-struct-1.c| 12 ++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-union-1.c   | 14 +++
 gcc/testsuite/gcc.dg/debug/ctf/ctf-variables-1.c   | 25 
 37 files changed, 966 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/debug/ctf/ctf-2.c
 create mode 10

[PATCH,RFC,V5 6/6] Handle CTF sections when LTO is enabled

2019-09-08 Thread Indu Bhagat
libiberty/ChangeLog:

* simple-object.c (handle_lto_debug_sections): Copy CTF section.

---
 libiberty/ChangeLog   | 5 +
 libiberty/simple-object.c | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/libiberty/simple-object.c b/libiberty/simple-object.c
index b00c265..96bdcf8 100644
--- a/libiberty/simple-object.c
+++ b/libiberty/simple-object.c
@@ -298,6 +298,9 @@ handle_lto_debug_sections (const char *name, int rename)
  COMDAT sections in objects produced by GCC.  */
   else if (strcmp (name, ".comment") == 0)
 return strcpy (newname, name);
+  /* Copy over .ctf section under the same name if present.  */
+  else if (strcmp (name, ".ctf") == 0)
+return strcpy (newname, name);
   free (newname);
   return NULL;
 }
-- 
1.8.3.1



[PATCH,RFC,V5 4/6] CTF generation for a single compilation unit

2019-09-08 Thread Indu Bhagat
For each translation unit, a CTF container (ctf_container_t) is used to
keep the CTF debug info.

- ctfout.c hosts the compiler facing routines for CTF generation and emission.
- ctfcreate.c contains the CTF format specific CTF creation routines.
- ctfutils.c contains helper routines for CTF creation.

[Changes from V4]
 Bugfixes and Enhancements:
  - Use DECL_UID () instead of htab_hash_pointer () for _DECL
  - Handle boolean and zero-sized bitfields
  - Do not inform () when skipping types.  Arguably this was intended for the
GCC developer and not for the end user.
  - Other bugfixes around de-dupilication at the time of CTF Array or CTF
function generation.

gcc/ChangeLog
 
* Makefile.in: Add new object files.
* ctfcreate.c: New file.
* ctfout.c (ctf_dtu_d_union_selector): New helper function for garbage
collection of dtd_u union in ctf_dtdef_t.
(ctfc_add_cuname): New function to add compilation unit name to CTF
container.
(ctf_dtdef_hash::hash): New function to generate hashkey for a CTF type
record.
(hash_dtd_tree_decl): New function.
(ctf_dtdef_hash::equal): Likewise.
(is_ctf_base_type): Likewise.
(get_cvr_quals_for_type): Likewise.
(get_type_name_string): Likewise.
(get_decl_name_string): Likewise.
(ctf_type_exists): Likewise.
(init_ctf_string_table): Likewise.
(new_ctf_container): Allocate contents of CTF container.
(delete_ctf_container): Cleanup contents of CTF container.
(init_ctf_sections): Update code comments regarding LTO.
(gen_ctf_base_type): New function.
(gen_ctf_pointer_type): Likewise.
(gen_ctf_array_type): Likewise.
(gen_ctf_forward_type): Likewise.
(gen_ctf_enum_const_list): Likewise.
(gen_ctf_enum_type): Likewise.
(gen_ctf_function_type): Likewise.
(gen_ctf_cvrquals): Likewise.
(gen_ctf_sou_type): Likewise.
(gen_ctf_typedef): Likewise.
(gen_ctf_variable): Likewise.
(gen_ctf_function): Likewise.
(gen_ctf_type): Likewise.
(gen_ctf_bitfield_type_for_decl): Likewise.
(gen_ctf_type_for_decl): Likewise.
(ctf_preprocess_var): Likewise.
(ctf_dvd_preprocess_cb): Likewise.
(ctf_dtd_preprocess_cb): Likewise.
(ctf_preprocess): Likewise.
(ctf_asm_preamble): Likewise.
(ctf_asm_stype): Likewise.
(ctf_asm_type): Likewise.
(ctf_asm_slice): Likewise.
(ctf_asm_array): Likewise.
(ctf_asm_varent): Likewise.
(ctf_asm_sou_lmember): Likewise.
(ctf_asm_sou_member): Likewise.
(ctf_asm_enum_const): Likewise.
(output_ctf_header): Output the CTF section if the CTF container is not
empty.
(output_ctf_obj_info): New function.
(output_ctf_func_info): Likewise.
(output_ctf_objtidx): Likewise.
(output_ctf_funcidx): Likewise.
(output_ctf_vars): Likewise.
(output_ctf_strs): Likewise.
(output_asm_ctf_sou_fields): Likewise.
(output_asm_ctf_enum_list): Likewise.
(output_asm_ctf_vlen_bytes): Likewise.
(output_asm_ctf_type): Likewise.
(output_ctf_types): Likewise.
(ctf_decl): Likewise.
(ctf_early_finish): Trigger CTF emission.
(ctf_early_global_decl): Invoke CTF generation function.
(ctfout_c_finalize): Add cleanup of CTF container.
* ctfout.h (typedef struct GTY): New data structures.
(struct ctf_dtdef_hash): CTF type structure hasher.
* ctfutils.c: New file.

include/ChangeLog:
 
* ctf.h: Sync with binutils.  Keep ctf_slice_t aligned.  Add CTF obj
index and func index section.

---
 gcc/ChangeLog |   70 ++
 gcc/Makefile.in   |2 +
 gcc/ctfcreate.c   |  557 
 gcc/ctfout.c  | 1828 -
 gcc/ctfout.h  |  317 +-
 gcc/ctfutils.c|  198 ++
 include/ChangeLog |5 +
 include/ctf.h |   59 +-
 8 files changed, 2986 insertions(+), 50 deletions(-)
 create mode 100644 gcc/ctfcreate.c
 create mode 100644 gcc/ctfutils.c

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 62d9256..38ff0be 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1257,6 +1257,8 @@ OBJS = \
cfgloopmanip.o \
cfgrtl.o \
ctfout.o \
+   ctfutils.o \
+   ctfcreate.o \
symtab.o \
cgraph.o \
cgraphbuild.o \
diff --git a/gcc/ctfcreate.c b/gcc/ctfcreate.c
new file mode 100644
index 000..52c9821
--- /dev/null
+++ b/gcc/ctfcreate.c
@@ -0,0 +1,557 @@
+/* Functions to create and update CTF from GCC.
+   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