Re: Add "fast" conversions from arrays to bitmaps

2019-09-17 Thread Richard Sandiford
Martin Liška  writes:
>> +··static·size_t·size·(const·T·(&x)[N])·{·return·N;·} 
>
> Hello.
>
> This leads to a clang warning:
>
> gcc/array-traits.h:45:33: warning: unused parameter 'x' [-Wunused-parameter]
>
> Can you please fix it?
> Thanks,
> Martin

Sure, done as follows, committed as r275805.


2019-09-17  Richard Sandiford  

gcc/
* array-traits.h (array_traits::size): Remove parameter name.

Index: gcc/array-traits.h
===
--- gcc/array-traits.h  2019-09-09 19:01:40.367078300 +0100
+++ gcc/array-traits.h  2019-09-17 15:27:38.537865469 +0100
@@ -42,7 +42,7 @@ struct array_traits
   static const bool has_constant_size = true;
   static const size_t constant_size = N;
   static const T *base (const T (&x)[N]) { return x; }
-  static size_t size (const T (&x)[N]) { return N; }
+  static size_t size (const T (&)[N]) { return N; }
 };
 
 #endif


Re: Add "fast" conversions from arrays to bitmaps

2019-09-16 Thread Martin Liška
+··static·size_t·size·(const·T·(&x)[N])·{·return·N;·} 


Hello.

This leads to a clang warning:

gcc/array-traits.h:45:33: warning: unused parameter 'x' [-Wunused-parameter]

Can you please fix it?
Thanks,
Martin


Re: Add "fast" conversions from arrays to bitmaps

2019-09-09 Thread Jeff Law
On 9/9/19 10:32 AM, Richard Sandiford wrote:
> This patch adds a bitmap_view class that creates a read-only,
> on-stack bitmap representation of an array-like object X.  The main
> use case is to allow HARD_REG_SETs to be used in REG_SET (i.e. bitmap)
> operations.
> 
> For now it only handles constant-sized arrays, but I've tried to
> define the types in a way that could handle variable-sized arrays
> in future (although less efficiently).  E.g. this might be useful
> for combining bitmaps and sbitmaps.
> 
> For the read-only view to work as intended, I needed to make
> bitmap_bit_p take a const_bitmap instead of a bitmap.  Logically
> the bitmap really is read-only, but we update the "current" and
> "indx" fields of the bitmap_head after doing a search.
> 
> The patch makes this change using a const_cast.  Another option
> was to make the fields mutable and push the constness down to
> bitmap_list_find_element and bitmap_tree_find_element.
> However, the constness of const_bitmap should apply to the bitmap
> as a whole rather than just the head structure, so if the input
> to those functions is a const_bitmap, the result should be a
> "const bitmap_element *".  We'd therefore need overloaded versions of
> bitmap_*_find_element that take a constant bitmap and return a constant
> element (as for standard container accessors).  These would be wrappers
> around the non-constant versions and themselves need a const_cast.
> All that seemed a bit over-the-top for an internal interface.
> 
> I experimented with a few ways of writing the constructors, but the
> attached gave the best code.  E.g. (for x86_64 users):
> 
> void
> foo (bitmap a, const_hard_reg_set b)
> {
>   bitmap_ior_into (a, bitmap_view (b));
> }
> 
> becomes:
> 
> .cfi_startproc
> subq$88, %rsp
> .cfi_def_cfa_offset 96
> movq(%rsi), %rdx
> movq8(%rsi), %rax
> movq$0, (%rsp)
> movq$0, 8(%rsp)
> movq%rdx, %rcx
> movq$0, 16(%rsp)
> orq %rax, %rcx
> movq$0, 24(%rsp)
> je  .L645
> leaq32(%rsp), %rcx
> movl$0, 48(%rsp)
> movq%rcx, 8(%rsp)
> movq$0, 40(%rsp)
> movq$0, 32(%rsp)
> movq%rcx, 16(%rsp)
> movq%rdx, 56(%rsp)
> movq%rax, 64(%rsp)
> .L645:
> movq%rsp, %rsi
> call_Z15bitmap_ior_intoP11bitmap_headPKS_
> addq$88, %rsp
> .cfi_def_cfa_offset 8
> ret
> 
> which ought to be more efficient than the loops that the patch
> is replacing.
> 
> Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?
> 
> Richard
> 
> 
> 2019-09-09  Richard Sandiford  
> 
> gcc/
>   * array-traits.h: New file.
>   * coretypes.h (array_traits, bitmap_view): New types.
>   * bitmap.h: Include "array-traits.h"
>   (bitmap_bit_p): Take a const_bitmap instead of a bitmap.
>   (base_bitmap_view, bitmap_view): New classes.
>   * bitmap.c (bitmap_bit_p): Take a const_bitmap instead of a bitmap.
>   * hard-reg-set.h: Include array-traits.h.
>   (array_traits): New struct.
>   * regset.h (IOR_REG_SET_HRS): New macro.
>   * loop-iv.c (simplify_using_initial_values): Use IOR_REG_SET_HRS
>   rather than iterating over each hard register.
>   * sched-deps.c (sched_analyze_insn): Likewise.
>   * sel-sched-ir.c (setup_id_implicit_regs): Likewise.
OK
jeff


Add "fast" conversions from arrays to bitmaps

2019-09-09 Thread Richard Sandiford
This patch adds a bitmap_view class that creates a read-only,
on-stack bitmap representation of an array-like object X.  The main
use case is to allow HARD_REG_SETs to be used in REG_SET (i.e. bitmap)
operations.

For now it only handles constant-sized arrays, but I've tried to
define the types in a way that could handle variable-sized arrays
in future (although less efficiently).  E.g. this might be useful
for combining bitmaps and sbitmaps.

For the read-only view to work as intended, I needed to make
bitmap_bit_p take a const_bitmap instead of a bitmap.  Logically
the bitmap really is read-only, but we update the "current" and
"indx" fields of the bitmap_head after doing a search.

The patch makes this change using a const_cast.  Another option
was to make the fields mutable and push the constness down to
bitmap_list_find_element and bitmap_tree_find_element.
However, the constness of const_bitmap should apply to the bitmap
as a whole rather than just the head structure, so if the input
to those functions is a const_bitmap, the result should be a
"const bitmap_element *".  We'd therefore need overloaded versions of
bitmap_*_find_element that take a constant bitmap and return a constant
element (as for standard container accessors).  These would be wrappers
around the non-constant versions and themselves need a const_cast.
All that seemed a bit over-the-top for an internal interface.

I experimented with a few ways of writing the constructors, but the
attached gave the best code.  E.g. (for x86_64 users):

void
foo (bitmap a, const_hard_reg_set b)
{
  bitmap_ior_into (a, bitmap_view (b));
}

becomes:

.cfi_startproc
subq$88, %rsp
.cfi_def_cfa_offset 96
movq(%rsi), %rdx
movq8(%rsi), %rax
movq$0, (%rsp)
movq$0, 8(%rsp)
movq%rdx, %rcx
movq$0, 16(%rsp)
orq %rax, %rcx
movq$0, 24(%rsp)
je  .L645
leaq32(%rsp), %rcx
movl$0, 48(%rsp)
movq%rcx, 8(%rsp)
movq$0, 40(%rsp)
movq$0, 32(%rsp)
movq%rcx, 16(%rsp)
movq%rdx, 56(%rsp)
movq%rax, 64(%rsp)
.L645:
movq%rsp, %rsi
call_Z15bitmap_ior_intoP11bitmap_headPKS_
addq$88, %rsp
.cfi_def_cfa_offset 8
ret

which ought to be more efficient than the loops that the patch
is replacing.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Richard


2019-09-09  Richard Sandiford  

gcc/
* array-traits.h: New file.
* coretypes.h (array_traits, bitmap_view): New types.
* bitmap.h: Include "array-traits.h"
(bitmap_bit_p): Take a const_bitmap instead of a bitmap.
(base_bitmap_view, bitmap_view): New classes.
* bitmap.c (bitmap_bit_p): Take a const_bitmap instead of a bitmap.
* hard-reg-set.h: Include array-traits.h.
(array_traits): New struct.
* regset.h (IOR_REG_SET_HRS): New macro.
* loop-iv.c (simplify_using_initial_values): Use IOR_REG_SET_HRS
rather than iterating over each hard register.
* sched-deps.c (sched_analyze_insn): Likewise.
* sel-sched-ir.c (setup_id_implicit_regs): Likewise.

Index: gcc/array-traits.h
===
--- /dev/null   2019-07-30 08:53:31.317691683 +0100
+++ gcc/array-traits.h  2019-09-09 17:23:00.736796759 +0100
@@ -0,0 +1,48 @@
+/* Descriptions of array-like objects.
+   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
+.  */
+
+#ifndef GCC_ARRAY_TRAITS_H
+#define GCC_ARRAY_TRAITS_H
+
+/* Implementation for single integers (and similar types).  */
+template
+struct scalar_array_traits
+{
+  typedef T element_type;
+  static const bool has_constant_size = true;
+  static const size_t constant_size = 1;
+  static const T *base (const T &x) { return &x; }
+  static size_t size (const T &) { return 1; }
+};
+
+template
+struct array_traits : scalar_array_traits {};
+
+/* Implementation for arrays with a static size.  */
+template
+struct array_traits
+{
+  typedef T element_type;
+  static const bool has_constant_size = true;
+  static const size_t constant_size = N;
+  static const T *base (const T (&x)[N]) { return x; }
+  static size_t size (const T (&x)[N]) { return N; }
+};
+
+#endif