[patch sdbout]: Fix ICE on -debug testsuite test const2.C for coff

2014-11-06 Thread Kai Tietz
Hi,

This fixes recent fallout of debug-tests on Windows target for sdbout
(coff) caused by an ICE.

ChangeLog

2014-11-06  Kai Tietz  kti...@redhat.com

* sdbout.c (sdbout_symbol): Eliminate register only
if decl isn't a global variable.


Tested for i686-w64-mingw32, and x86_64-w64-mingw32.  Ok for apply?

Regards,
Kai

Index: sdbout.c
===
--- sdbout.c(Revision 217175)
+++ sdbout.c(Arbeitskopie)
@@ -739,13 +739,16 @@ sdbout_symbol (tree decl, int local)
   if (!DECL_RTL_SET_P (decl))
 return;

-  SET_DECL_RTL (decl,
-eliminate_regs (DECL_RTL (decl), VOIDmode, NULL_RTX));
+  value = DECL_RTL (decl);
+
+  if (!is_global_var (decl))
+value = eliminate_regs (value, VOIDmode, NULL_RTX);
+
+  SET_DECL_RTL (decl, value);
 #ifdef LEAF_REG_REMAP
   if (crtl-uses_only_leaf_regs)
-leaf_renumber_regs_insn (DECL_RTL (decl));
+leaf_renumber_regs_insn (value);
 #endif
-  value = DECL_RTL (decl);

   /* Don't mention a variable at all
  if it was completely optimized into nothingness.


Re: [patch sdbout]: Fix ICE on -debug testsuite test const2.C for coff

2014-11-08 Thread Kai Tietz
Hi Jeff,

2014-11-07 21:03 GMT+01:00 Jeff Law l...@redhat.com:
 On 11/06/14 12:37, Kai Tietz wrote:

 Hi,

 This fixes recent fallout of debug-tests on Windows target for sdbout
 (coff) caused by an ICE.

 ChangeLog

 2014-11-06  Kai Tietz  kti...@redhat.com

  * sdbout.c (sdbout_symbol): Eliminate register only
  if decl isn't a global variable.

 Is there a testcase in the suite that triggers this problem?  If not, can
 you try to add one?Out of curiosity, what was DECL_RTL here?

Sure, as (partial) mentioned in subject-line the testcase
g++.dg/debug/const2.C: Triggers this issue.  So there is no need to
add a separate testcase for it. Testcase fails for any use of -gcoff1
option.

 This is probably OK, but I'd really like to know what kind of goofy RTL we
 passed to eliminate_regs that caused it to fail.

I assume it is ok, as I just mimic dwarf2-behavior, which checks
before call for eliminate_regs, if rtl isn't a global-var itself.

As assumed by checking in debugger I see that eliminate_regs fails on rtx:
(mem/u/c:SI (symbol_ref:DI (_ZN1b1dE) [flags 0x2] var_decl 0xffbf d) [0
d+0 S4 A32])



 Jeff


So a more general question about sdbout.   Most prior dbg-coff targets
using nowadays dwarf2 too.  It seems to me that sdbout didn't got any
substantial maintenance the last years anymore.  Just fallout was
fixed.  AFAIK is coff (or was) mainly used nowadays for embedded
stuff, and in combination with some tools just supporting coff-dbg
information. Do we actually need to support it anymore?

Kai


Re: [ping*3] fix build failure of x86_64-mingw32, missing crtbegin/crtend.o

2014-09-17 Thread Kai Tietz
Hello Oliver,

Sorry for the delay in review.  Patch looks ok.  Have you just tested
-pc- variant, or also -w64- one?

Thanks,
Kai


Re: [ping*3] fix build failure of x86_64-mingw32, missing crtbegin/crtend.o

2014-09-17 Thread Kai Tietz
2014-09-17 12:38 GMT+02:00 Olivier Hainque hain...@adacore.com:
 Hello Kai,

 On Sep 17, 2014, at 10:52 , Kai Tietz ktiet...@googlemail.com wrote:

 Sorry for the delay in review.

  No problem at all. Thanks for your feedback :)

  Patch looks ok.  Have you just tested
 -pc- variant, or also -w64- one?

  Just the -pc- variant, by our nightly builders.

  We probably could twist our configuration scripts to experiment the -w64-
  variant as well.  Might take a bit of time though.

Well, would be interesting.  As you are using for 64-bit anyway
mingw-w64's runtime, it doesn't make here any difference AFAICS.  The
-pc- vs. the -w64- varaint just controls the enabling of some
additional features.  So said, -pc- is legacy version.

  AFAICS, the w64 variant resorts to the crtstuff objects as well and there's
  no special case for -w64 in libgcc/config.host, so it really looks like the
  change is needed for this variant also.

  Regards,

  Olivier

So, patch is ok. Please apply patch to trunk.

Kai


Re: [patch i386]: Sibcall tail-call improvement and partial fix PR/60104

2014-09-18 Thread Kai Tietz
Hi,

it isn't true that I didn't replied to Iant.  I did this on IRC.  As I
explained there already, this hunk about thunks is more consolidation
of code-paths in that function, and not really part of a feature.  As
this code-path isn't prominent mark being Darwin-code - and please
don't take me wrong, but it seems to be until now the only target
reporting this issues - and therefore I strongly see the issue to be
solved for Darwin.   I don't see that this changes needs an additional
testcase demonstration on a already regression-tested target that it
doesn't break ... This is somehow like asking for gcc-testcase
demostration that gcc's darwin target isn't responsible for earth's
warming ...

Nevertheless I provided in the past already a patch which fixes the
issue well.  As underlying issue seems to be that gotpcrel relocations
aren't suitable for call-instruction's address on Darwin's target. So
disallowing for this the use via the operand-check-predicate is the
right thing to do. As this prevents in all cases that for this target
such a construct might be generated even for none-thunk case, which
seems btw not being problematic at all.

I don't agree to revert that patch.  Please provide a testcase, why my
suggested fix isn't suitable.

Regards,
Kai


Re: [patch i386]: Sibcall tail-call improvement and partial fix PR/60104

2014-09-18 Thread Kai Tietz
2014-09-18 23:35 GMT+02:00 FX fxcoud...@gmail.com:
 Dear Kai,

 it isn't true that I didn't replied to Iant.  I did this on IRC.

 Good. I simply did not see any recent comment from you on the list, or 
 bugzilla.

 As
 this code-path isn't prominent mark being Darwin-code - and please
 don't take me wrong, but it seems to be until now the only target
 reporting this issues

 Sure, no problem. There are many code-paths in the compiler that are only 
 taken on a subset of targets, so noone is implying that you should have 
 tested it on all targets before committing.


 - and therefore I strongly see the issue to be
 solved for Darwin.   I don't see that this changes needs an additional
 testcase demonstration on a already regression-tested target that it
 doesn't break ...

 I'm afraid I don't understand what you mean by that. I was only saying that 
 if this part of the patch is only exercised on darwin, and it fails there, we 
 might want to change it.

 Nevertheless I provided in the past already a patch which fixes the
 issue well.

 Could you give a link to the patch? I'm not finding it. Has it been tested on 
 darwin? If not, I can do it.

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61387 comment #9.  It
doesn't apply anymore due current version of predicate was altered.
Nevertheless I could easily update patch for current trunk version.


 I don't agree to revert that patch.  Please provide a testcase, why my
 suggested fix isn't suitable.

 If there is a patch submitted that fixes the issue, of course reversion is 
 bad. I was unaware of that.

 FX

Kai


Re: [patch i386]: Sibcall tail-call improvement and partial fix PR/60104

2014-09-18 Thread Kai Tietz
Here it is. Hope I didn't made here typos.

Kai

Index: config/i386/predicates.md
===
--- config/i386/predicates.md   (Revision 215364)
+++ config/i386/predicates.md   (Arbeitskopie)
@@ -73,8 +73,15 @@

 ;; Return true if OP is a memory operands that can be used in sibcalls.
 (define_predicate sibcall_memory_operand
-  (and (match_operand 0 memory_operand)
-   (match_test CONSTANT_P (XEXP (op, 0)
+  (match_operand 0 memory_operand)
+{
+  if (TARGET_MACHO  TARGET_64BIT
+   GET_CODE (op) == CONST
+   GET_CODE (XEXP (op, 0)) == UNSPEC
+   XINT (XEXP (op, 0), 1) == UNSPEC_GOTPCREL)
+return false;
+  return CONSTANT_P (XEXP (op, 0));
+})

 ;; Match an SI or HImode register for a zero_extract.
 (define_special_predicate ext_register_operand


Re: [patch i386]: Sibcall tail-call improvement and partial fix PR/60104

2014-09-20 Thread Kai Tietz
Hi FX,

I missed that op points still on the memory here.  So corrected patch
is inlined below.

Kai

Index: predicates.md
===
--- predicates.md   (Revision 215364)
+++ predicates.md   (Arbeitskopie)
@@ -73,9 +73,18 @@

 ;; Return true if OP is a memory operands that can be used in sibcalls.
 (define_predicate sibcall_memory_operand
-  (and (match_operand 0 memory_operand)
-   (match_test CONSTANT_P (XEXP (op, 0)
+  (match_operand 0 memory_operand)
+{
+  op = XEXP (op, 0);

+  if (TARGET_MACHO  TARGET_64BIT
+   GET_CODE (op) == CONST
+   GET_CODE (XEXP (op, 0)) == UNSPEC
+   XINT (XEXP (op, 0), 1) == UNSPEC_GOTPCREL)
+return false;
+  return CONSTANT_P (op);
+})
+
 ;; Match an SI or HImode register for a zero_extract.
 (define_special_predicate ext_register_operand
   (match_operand 0 register_operand)


[patch c/c++]: Fix for PR c/52991 issue about ignored packed-attribute for ms-structure-layout

2012-12-11 Thread Kai Tietz
Hello,

This fixes an old regression about ms-structure-layout in combination
with packed-attribute.

ChangeLog

2012-12-11  Kai Tietz

PR c/52991
* stor-layout.c (start_record_layout): Handle
packed-attribute for ms-structure-layout.
(update_alignment_for_field): Likewise.
(place_field): Likewise.


Tested for i686-w64-mingw32, x86_64-w64-mingw32, and for
x86_64-unknown-linux-gnu.  Ok for apply?

Regards,
Kai

Index: stor-layout.c
===
--- stor-layout.c   (Revision 194386)
+++ stor-layout.c   (Arbeitskopie)
@@ -756,7 +756,10 @@ start_record_layout (tree t)
   /* If the type has a minimum specified alignment (via an attribute
  declaration, for example) use it -- otherwise, start with a
  one-byte alignment.  */
-  rli-record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (t));
+  if (TYPE_PACKED (t))
+rli-record_align = BITS_PER_UNIT;
+  else
+rli-record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (t));
   rli-unpacked_align = rli-record_align;
   rli-offset_align = MAX (rli-record_align, BIGGEST_ALIGNMENT);

@@ -952,15 +955,20 @@ update_alignment_for_field (record_layout_info rli
  meaningless.  */
   if (targetm.ms_bitfield_layout_p (rli-t))
 {
+  if (rli-t  TYPE_PACKED (rli-t)
+   (is_bitfield || !DECL_PACKED (field)
+  || DECL_SIZE (field) == NULL_TREE
+  || !integer_zerop (DECL_SIZE (field
+desired_align = BITS_PER_UNIT;
   /* Here, the alignment of the underlying type of a bitfield can
 affect the alignment of a record; even a zero-sized field
 can do this.  The alignment should be to the alignment of
 the type, except that for zero-size bitfields this only
 applies if there was an immediately prior, nonzero-size
 bitfield.  (That's the way it is, experimentally.) */
-  if ((!is_bitfield  !DECL_PACKED (field))
- || ((DECL_SIZE (field) == NULL_TREE
-  || !integer_zerop (DECL_SIZE (field)))
+  else if ((!is_bitfield  !DECL_PACKED (field))
+  || ((DECL_SIZE (field) == NULL_TREE
+  || !integer_zerop (DECL_SIZE (field)))
  ? !DECL_PACKED (field)
  : (rli-prev_field
  DECL_BIT_FIELD_TYPE (rli-prev_field)
@@ -1414,7 +1422,13 @@ place_field (record_layout_info rli, tree field)
}

  /* Now align (conventionally) for the new type.  */
- type_align = TYPE_ALIGN (TREE_TYPE (field));
+ if (!TYPE_PACKED (rli-t))
+   {
+ type_align = TYPE_ALIGN (TREE_TYPE (field));
+ if (DECL_PACKED (field))
+   type_align = MIN (type_align, BITS_PER_UNIT);
+   
+   }

  if (maximum_field_alignment != 0)
type_align = MIN (type_align, maximum_field_alignment);


Re: [patch c/c++]: Fix for PR c/52991 issue about ignored packed-attribute for ms-structure-layout

2012-12-12 Thread Kai Tietz
2012/12/12 Richard Biener richard.guent...@gmail.com:
 On Wed, Dec 12, 2012 at 4:11 PM, Richard Henderson r...@redhat.com wrote:
 On 12/12/2012 02:57 AM, Richard Biener wrote:
 That looks wrong.  Having both TYPE_PACKED and TYPE_ALIGN != BITS_PER_UNIT
 is inconsistent, so this part of the patch should not be necessary.

 No, that is the only way to give a 4 byte int 2 byte alignment:
 use both packed and aligned attributes.

 struct S {
   char x;
   int y;
 };

 struct T {
   char x;
   int y __attribute__((aligned(2)));
 };

 struct U {
   char x;
   int y __attribute__((packed, aligned(2)));
 };

 int s_y = __builtin_offsetof(struct S, y);
 int t_y = __builtin_offsetof(struct T, y);
 int u_y = __builtin_offsetof(struct U, y);

 But the patch changes it for the RECORD_TYPE case and

 struct T __attribute__((packed,aligned(2))) {
char x;
short s;
char y;
short a;
 };
 struct T x;

 doesn't work as I would have expected (giving x.x and x.a 2-byte alignment).

 In fact, the type attribute docs for 'packed' only say that fields are packed,
 not that alignment of the type itself is affected (and 'aligned' is not 
 specifed
 in the docs for types at all it seems).

 Richard.

Hmm, I see the attribute aligned explicit mention for types.  See 5.33
Specifying Attributes of Types.
Well, the case to combine aligned and packed attribute seems indeed
not to be explicit mentioned.  Nevertheless documention tells for
packed-attribute for types This attribute, attached to `struct' or
`union' type definition, specifies that each member of the structure
or union is placed to minimize the memory required., which implies -
I might be wrong here - that an alignment of 1 is active by default.
So to put those two attributes wiithin one attribute doesn't make
sense, as either the aligned or the packed have to be interpreted.  To
specify within a packed-struct-type for a sepcific variable a special
alignment - as shown in Rth's testcase - makes sense and seems to be
covered by the docs.

Regards,
Kai


Re: [patch c/c++]: Fix for PR c/52991 issue about ignored packed-attribute for ms-structure-layout

2012-12-12 Thread Kai Tietz
Hi,

I added two testcases  to this patch.  So that we might detect
regressions about this issue later more easily.

2012-12-12  Kai Tietz

PR c/52991
* stor-layout.c (start_record_layout): Handle
packed-attribute for ms-structure-layout.
(update_alignment_for_field): Likewise.
(place_field): Likewise.

2012-12-12  Kai Tietz

PR c/52991
* gcc.dg/attr-ms_struct-packed2.c: New file.
* gcc.dg/attr-ms_struct-packed3.c: New file.

Ok for apply?

Regards,
Kai

Index: gcc/gcc/stor-layout.c
===
--- gcc.orig/gcc/stor-layout.c
+++ gcc/gcc/stor-layout.c
@@ -756,7 +756,10 @@ start_record_layout (tree t)
   /* If the type has a minimum specified alignment (via an attribute
  declaration, for example) use it -- otherwise, start with a
  one-byte alignment.  */
-  rli-record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (t));
+  if (TYPE_PACKED (t))
+rli-record_align = BITS_PER_UNIT;
+  else
+rli-record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (t));
   rli-unpacked_align = rli-record_align;
   rli-offset_align = MAX (rli-record_align, BIGGEST_ALIGNMENT);

@@ -952,15 +955,20 @@ update_alignment_for_field (record_layou
  meaningless.  */
   if (targetm.ms_bitfield_layout_p (rli-t))
 {
+  if (rli-t  TYPE_PACKED (rli-t)
+   (is_bitfield || !DECL_PACKED (field)
+  || DECL_SIZE (field) == NULL_TREE
+  || !integer_zerop (DECL_SIZE (field
+desired_align = BITS_PER_UNIT;
   /* Here, the alignment of the underlying type of a bitfield can
 affect the alignment of a record; even a zero-sized field
 can do this.  The alignment should be to the alignment of
 the type, except that for zero-size bitfields this only
 applies if there was an immediately prior, nonzero-size
 bitfield.  (That's the way it is, experimentally.) */
-  if ((!is_bitfield  !DECL_PACKED (field))
- || ((DECL_SIZE (field) == NULL_TREE
-  || !integer_zerop (DECL_SIZE (field)))
+  else if ((!is_bitfield  !DECL_PACKED (field))
+  || ((DECL_SIZE (field) == NULL_TREE
+  || !integer_zerop (DECL_SIZE (field)))
  ? !DECL_PACKED (field)
  : (rli-prev_field
  DECL_BIT_FIELD_TYPE (rli-prev_field)
@@ -1414,7 +1422,12 @@ place_field (record_layout_info rli, tre
}

  /* Now align (conventionally) for the new type.  */
- type_align = TYPE_ALIGN (TREE_TYPE (field));
+ if (!TYPE_PACKED (rli-t))
+   {
+ type_align = TYPE_ALIGN (TREE_TYPE (field));
+ if (DECL_PACKED (field))
+   type_align = MIN (type_align, BITS_PER_UNIT);
+   }

  if (maximum_field_alignment != 0)
type_align = MIN (type_align, maximum_field_alignment);
Index: gcc/gcc/testsuite/gcc.dg/attr-ms_struct-packed2.c
===
--- /dev/null
+++ gcc/gcc/testsuite/gcc.dg/attr-ms_struct-packed2.c
@@ -0,0 +1,31 @@
+/* Test for MS structure with packed attribute.  */
+/* { dg-do run { target *-*-interix* *-*-mingw* *-*-cygwin*
i?86-*-darwin* i?86-*-linux* x86_64-*-linux* } }
+/* { dg-options -std=gnu99 } */
+
+extern void abort ();
+
+struct A {
+short s;
+struct { int i; } __attribute__((__ms_struct__));
+} __attribute__((__ms_struct__, __packed__));
+
+struct B {
+short s;
+struct { int i; } __attribute__((__ms_struct__, __packed__));
+} __attribute__((__ms_struct__, __packed__));
+
+struct C {
+struct { int i; } __attribute__((__ms_struct__));
+short s;
+} __attribute__((__ms_struct__, __packed__));
+
+int
+main (void)
+{
+  if (sizeof (struct C) != sizeof (struct B)
+  || sizeof (struct A) != sizeof (struct B)
+  || sizeof (struct B) != 6)
+abort ();
+
+  return 0;
+}


Re: [patch c/c++]: Fix for PR c/52991 issue about ignored packed-attribute for ms-structure-layout

2012-12-13 Thread Kai Tietz
2012/12/13 Jakub Jelinek ja...@redhat.com:
 On Thu, Dec 13, 2012 at 11:29:47AM +0100, Richard Biener wrote:
 On Thu, Dec 13, 2012 at 11:07 AM, Jakub Jelinek ja...@redhat.com wrote:
  On Thu, Dec 13, 2012 at 11:03:58AM +0100, Richard Biener wrote:
  struct X
  {
char c;
short s;
char c2;
short s2;
  } __attribute__((packed,aligned(2)));
 
  As struct-layout-1.exp tests show, this is something that was ABI-wise
  changed already several times.  That said, for non-ms-bitfield-layout I'd
  strongly prefer if we could avoid yet another ABI change for it.

 Probably not exactly this case - 2.95, 3.2, 3.3, 4.1 ... all show the same
 behavior.  And Kai should have seen regressions, no?

 Maybe my memory is too weak, dunno if it was packed,aligned(N) or 
 aligned(N),packed,
 but I remember seeing FAILs in such tests when testing against older
 compilers.

Well, I see the point about having packed and aligned in combination
only for final-element in struct/union.  As packed enforces unaligned
accesses due it tries to save memory-use.  If an user alignment is
present the packing can just happen on last member for struct, as
otherwise the alignment has to be applied and padding happens.

But I agree that I didn't intended to change sysv_abi here by this
patch.  So I added to the change in start_record_layout a check to
ms-bitfields use.

2012-12-13  Kai Tietz

PR c/52991
* stor-layout.c (start_record_layout): Handle
packed-attribute for ms-structure-layout.
(update_alignment_for_field): Likewise.
(place_field): Likewise.

2012-12-12  Kai Tietz

PR c/52991
* gcc.dg/attr-ms_struct-packed2.c: New file.
* gcc.dg/attr-ms_struct-packed3.c: New file.

Ok for apply?

Regards,
Kai

Index: gcc/gcc/stor-layout.c
===
--- gcc.orig/gcc/stor-layout.c
+++ gcc/gcc/stor-layout.c
@@ -756,7 +756,10 @@ start_record_layout (tree t)
   /* If the type has a minimum specified alignment (via an attribute
  declaration, for example) use it -- otherwise, start with a
  one-byte alignment.  */
-  rli-record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (t));
+  if (targetm.ms_bitfield_layout_p (t)  TYPE_PACKED (t))
+rli-record_align = BITS_PER_UNIT;
+  else
+rli-record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (t));
   rli-unpacked_align = rli-record_align;
   rli-offset_align = MAX (rli-record_align, BIGGEST_ALIGNMENT);

@@ -952,15 +955,20 @@ update_alignment_for_field (record_layou
  meaningless.  */
   if (targetm.ms_bitfield_layout_p (rli-t))
 {
+  if (rli-t  TYPE_PACKED (rli-t)
+   (is_bitfield || !DECL_PACKED (field)
+  || DECL_SIZE (field) == NULL_TREE
+  || !integer_zerop (DECL_SIZE (field
+desired_align = BITS_PER_UNIT;
   /* Here, the alignment of the underlying type of a bitfield can
 affect the alignment of a record; even a zero-sized field
 can do this.  The alignment should be to the alignment of
 the type, except that for zero-size bitfields this only
 applies if there was an immediately prior, nonzero-size
 bitfield.  (That's the way it is, experimentally.) */
-  if ((!is_bitfield  !DECL_PACKED (field))
- || ((DECL_SIZE (field) == NULL_TREE
-  || !integer_zerop (DECL_SIZE (field)))
+  else if ((!is_bitfield  !DECL_PACKED (field))
+  || ((DECL_SIZE (field) == NULL_TREE
+  || !integer_zerop (DECL_SIZE (field)))
  ? !DECL_PACKED (field)
  : (rli-prev_field
  DECL_BIT_FIELD_TYPE (rli-prev_field)
@@ -1414,7 +1422,12 @@ place_field (record_layout_info rli, tre
}

  /* Now align (conventionally) for the new type.  */
- type_align = TYPE_ALIGN (TREE_TYPE (field));
+ if (!TYPE_PACKED (rli-t))
+   {
+ type_align = TYPE_ALIGN (TREE_TYPE (field));
+ if (DECL_PACKED (field))
+   type_align = MIN (type_align, BITS_PER_UNIT);
+   }

  if (maximum_field_alignment != 0)
type_align = MIN (type_align, maximum_field_alignment);
Index: gcc/gcc/testsuite/gcc.dg/attr-ms_struct-packed2.c
===
--- /dev/null
+++ gcc/gcc/testsuite/gcc.dg/attr-ms_struct-packed2.c
@@ -0,0 +1,31 @@
+/* Test for MS structure with packed attribute.  */
+/* { dg-do run { target *-*-interix* *-*-mingw* *-*-cygwin*
i?86-*-darwin* i?86-*-linux* x86_64-*-linux* } }
+/* { dg-options -std=gnu99 } */
+
+extern void abort ();
+
+struct A {
+short s;
+struct { int i; } __attribute__((__ms_struct__));
+} __attribute__((__ms_struct__, __packed__));
+
+struct B {
+short s;
+struct { int i; } __attribute__((__ms_struct__, __packed__));
+} __attribute__((__ms_struct__, __packed__));
+
+struct C {
+struct { int i; } __attribute__((__ms_struct__));
+short s

[patch libstdc++]: Fix LLP64 pointer-size issues for cxxabi, eh_alloc, and hash_bytes

2012-12-21 Thread Kai Tietz
Hello,

this patch fixes some remaining issues with pointer-sizes for llp64
abi in libstdc++.

ChangeLog

2012-12-21  Kai Tietz

* config/os/mingw32/os_defines.h (_GLIBCXX_LLP64): Define if llp64
abi is used.
* config/os/mingw32-w64/os_defines.h: Likewise.
* libsupc++/cxxabi.h (__base_class_type_info): Change
type __offset_flags to intptr_t.
* libsupc++/eh_alloc.cc (EMERGENCY_OBJ_SIZE): Define proper
for llp64 abi.
(EMERGENCY_OBJ_COUNT): Likewise.
(bitmask_type): Likewise.
* ibsupc++/hash_bytes.cc (_Hash_bytes): Handle llp64.

Tested for i686-w64-mingw32, x86_64-w64-mingw32, and
x86_64-unknown-linux-gnu.  Ok for apply?

Regards,
Kai

Index: config/os/mingw32/os_defines.h
===
--- config/os/mingw32/os_defines.h  (Revision 194655)
+++ config/os/mingw32/os_defines.h  (Arbeitskopie)
@@ -72,4 +72,8 @@
 #define _GLIBCXX_CDTOR_CALLABI __thiscall
 #endif

+#ifdef __x86_64__
+#define _GLIBCXX_LLP64 1
 #endif
+
+#endif
Index: config/os/mingw32-w64/os_defines.h
===
--- config/os/mingw32-w64/os_defines.h  (Revision 194655)
+++ config/os/mingw32-w64/os_defines.h  (Arbeitskopie)
@@ -74,4 +74,8 @@
 #define _GLIBCXX_CDTOR_CALLABI __thiscall
 #endif

+#ifdef __x86_64__
+#define _GLIBCXX_LLP64 1
 #endif
+
+#endif
Index: libsupc++/cxxabi.h
===
--- libsupc++/cxxabi.h  (Revision 194655)
+++ libsupc++/cxxabi.h  (Arbeitskopie)
@@ -356,7 +356,7 @@ namespace __cxxabiv1
   {
   public:
 const __class_type_info*   __base_type;  // Base class type.
-long   __offset_flags;  // Offset and info.
+intptr_t   __offset_flags;  // Offset and info.

 enum __offset_flags_masks
   {
Index: libsupc++/eh_alloc.cc
===
--- libsupc++/eh_alloc.cc   (Revision 194655)
+++ libsupc++/eh_alloc.cc   (Arbeitskopie)
@@ -60,7 +60,7 @@ using namespace __cxxabiv1;
 #if INT_MAX == 32767
 # define EMERGENCY_OBJ_SIZE128
 # define EMERGENCY_OBJ_COUNT   16
-#elif LONG_MAX == 2147483647
+#elif !defined (_GLIBCXX_LLP64)  LONG_MAX == 2147483647
 # define EMERGENCY_OBJ_SIZE512
 # define EMERGENCY_OBJ_COUNT   32
 #else
@@ -76,8 +76,12 @@ using namespace __cxxabiv1;
 #if INT_MAX == 32767 || EMERGENCY_OBJ_COUNT = 32
 typedef unsigned int bitmask_type;
 #else
+#if defined (_GLIBCXX_LLP64)
+typedef unsigned long long bitmask_type;
+#else
 typedef unsigned long bitmask_type;
 #endif
+#endif


 typedef char one_buffer[EMERGENCY_OBJ_SIZE] __attribute__((aligned));
Index: libsupc++/hash_bytes.cc
===
--- libsupc++/hash_bytes.cc (Revision 194655)
+++ libsupc++/hash_bytes.cc (Arbeitskopie)
@@ -128,7 +128,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   size_t
   _Hash_bytes(const void* ptr, size_t len, size_t seed)
   {
-static const size_t mul = (0xc6a4a793UL  32UL) + 0x5bd1e995UL;
+static const size_t mul = (((size_t) 0xc6a4a793UL)  32UL)
+ + (size_t) 0x5bd1e995UL;
 const char* const buf = static_castconst char*(ptr);

 // Remove the bytes not divisible by the sizeof(size_t).  This


Re: [patch libstdc++]: Fix LLP64 pointer-size issues for cxxabi, eh_alloc, and hash_bytes

2012-12-21 Thread Kai Tietz
2012/12/21 Paolo Carlini paolo.carl...@oracle.com:
 Hi,


 On 12/21/2012 08:59 AM, Kai Tietz wrote:

 Index: libsupc++/cxxabi.h
 ===
 --- libsupc++/cxxabi.h  (Revision 194655)
 +++ libsupc++/cxxabi.h  (Arbeitskopie)
 @@ -356,7 +356,7 @@ namespace __cxxabiv1
 {
 public:
   const __class_type_info*  __base_type;  // Base class type.
 -long   __offset_flags;  // Offset and info.
 +intptr_t   __offset_flags;  // Offset and info.

 I don't think this is a safe change, in the sense that intptr_t is in
 general only available on targets providing the C99 stdint.h.

 Paolo.

Well, I thought it is always present for gcc due gstdint.h header, but
well, using ptrdiff_t here instead would be ok too IMHO, and later is
compatible to none C99-systems.

Ok, with that change (and remove of later cast to ptrdiff_t for it)?

Kai


Re: [patch libstdc++]: Fix LLP64 pointer-size issues for cxxabi, eh_alloc, and hash_bytes

2012-12-21 Thread Kai Tietz
2012/12/21 Paolo Carlini paolo.carl...@oracle.com:
 Hi,


 On 12/21/2012 10:16 AM, Kai Tietz wrote:

 Well, I thought it is always present for gcc due gstdint.h header,

 As far as I know, that project isn't finished yet, there are still targets
 which neither provide the header, neither GCC synthetizes it. See also
 dg-require-effective-target stdint_types.

 but well, using ptrdiff_t here instead would be ok too IMHO, and later is
 compatible to none C99-systems. Ok, with that change (and remove of later
 cast to ptrdiff_t for it)?

 Are we 100% sure that, besides the targets we know well and love, elsewhere
 long is always == ptrdiff_t?

 Paolo.

well, issue isn't that 'long' is always 'ptrdiff_t'.  As this is
indeed the wrong assumption here.  As we treat here pointers later-one
as pointer-diff, it doesn't make any difference, even if pointer-size
might exceed 'ptrdiff_t' (well size_t would have here the same issue,
and all in all we lack a longptr_t type-definition in standard), then
we still don't change behavior AFAICS.

Kai


Re: [patch libstdc++]: Fix LLP64 pointer-size issues for cxxabi, eh_alloc, and hash_bytes

2012-12-21 Thread Kai Tietz
2012/12/21 Paolo Carlini paolo.carl...@oracle.com:
 On 12/21/2012 10:36 AM, Kai Tietz wrote:

 well, issue isn't that 'long' is always 'ptrdiff_t'.

 But then, if we just change the type without paying attention to size (and
 alignment) aren't we looking for BIG ABI trouble?!?

Huh?  We have ABI-trouble due long is  too small to hold a
pointer-diff for llp64.  Intended is here 'pointer-size' AFAICS in
code, but with wrong assumption that a 'long' is always long enough.

 Btw I just checked all targets we have right now in gcc.  The type
ptrdiff_t is always either 'long', or 'int' (ilp32, lp64), and 'long
long' for LLP64.  Means ptrdiff_t gets always equal (or bigger) to
biggest pointer-size for target (AFAICS).

Kai


Re: [patch libstdc++]: Fix LLP64 pointer-size issues for cxxabi, eh_alloc, and hash_bytes

2012-12-21 Thread Kai Tietz
Hello,

I changed type in __base_class_type_info to wide-enough type only for
llp64 target.
By this we have no (new) side-effects to other targets.

ChangeLog

2012-12-21  Kai Tietz

* config/os/mingw32/os_defines.h (_GLIBCXX_LLP64): Define if llp64
abi is used.
* config/os/mingw32-w64/os_defines.h: Likewise.
* libsupc++/cxxabi.h (__base_class_type_info): Adjust
type of __offset_flags for llp64.
* libsupc++/eh_alloc.cc (EMERGENCY_OBJ_SIZE): Define proper
for llp64 abi.
(EMERGENCY_OBJ_COUNT): Likewise.
(bitmask_type): Likewise.
* ibsupc++/hash_bytes.cc (_Hash_bytes): Handle llp64.

Tested for i686-w64-mingw32, x86_64-w64-mingw32, and
x86_64-unknown-linux-gnu.  Ok for apply?

Regards,
Kai

Index: config/os/mingw32/os_defines.h
===
--- config/os/mingw32/os_defines.h  (Revision 194655)
+++ config/os/mingw32/os_defines.h  (Arbeitskopie)
@@ -72,4 +72,8 @@
 #define _GLIBCXX_CDTOR_CALLABI __thiscall
 #endif

+#ifdef __x86_64__
+#define _GLIBCXX_LLP64 1
 #endif
+
+#endif
Index: config/os/mingw32-w64/os_defines.h
===
--- config/os/mingw32-w64/os_defines.h  (Revision 194655)
+++ config/os/mingw32-w64/os_defines.h  (Arbeitskopie)
@@ -74,4 +74,8 @@
 #define _GLIBCXX_CDTOR_CALLABI __thiscall
 #endif

+#ifdef __x86_64__
+#define _GLIBCXX_LLP64 1
 #endif
+
+#endif
Index: libsupc++/cxxabi.h
===
--- libsupc++/cxxabi.h  (Revision 194655)
+++ libsupc++/cxxabi.h  (Arbeitskopie)
@@ -356,7 +356,11 @@ namespace __cxxabiv1
   {
   public:
 const __class_type_info*   __base_type;  // Base class type.
+#ifdef _GLIBCXX_LLP64
+long long  __offset_flags;  // Offset and info.
+#else
 long   __offset_flags;  // Offset and info.
+#endif

 enum __offset_flags_masks
   {
Index: libsupc++/eh_alloc.cc
===
--- libsupc++/eh_alloc.cc   (Revision 194655)
+++ libsupc++/eh_alloc.cc   (Arbeitskopie)
@@ -60,7 +60,7 @@ using namespace __cxxabiv1;
 #if INT_MAX == 32767
 # define EMERGENCY_OBJ_SIZE128
 # define EMERGENCY_OBJ_COUNT   16
-#elif LONG_MAX == 2147483647
+#elif !defined (_GLIBCXX_LLP64)  LONG_MAX == 2147483647
 # define EMERGENCY_OBJ_SIZE512
 # define EMERGENCY_OBJ_COUNT   32
 #else
@@ -76,8 +76,12 @@ using namespace __cxxabiv1;
 #if INT_MAX == 32767 || EMERGENCY_OBJ_COUNT = 32
 typedef unsigned int bitmask_type;
 #else
+#if defined (_GLIBCXX_LLP64)
+typedef unsigned long long bitmask_type;
+#else
 typedef unsigned long bitmask_type;
 #endif
+#endif


 typedef char one_buffer[EMERGENCY_OBJ_SIZE] __attribute__((aligned));
Index: libsupc++/hash_bytes.cc
===
--- libsupc++/hash_bytes.cc (Revision 194655)
+++ libsupc++/hash_bytes.cc (Arbeitskopie)
@@ -128,7 +128,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   size_t
   _Hash_bytes(const void* ptr, size_t len, size_t seed)
   {
-static const size_t mul = (0xc6a4a793UL  32UL) + 0x5bd1e995UL;
+static const size_t mul = (((size_t) 0xc6a4a793UL)  32UL)
+ + (size_t) 0x5bd1e995UL;
 const char* const buf = static_castconst char*(ptr);

 // Remove the bytes not divisible by the sizeof(size_t).  This
Index: testsuite/18_support/50594.cc
===
--- testsuite/18_support/50594.cc   (Revision 194655)
+++ testsuite/18_support/50594.cc   (Arbeitskopie)
@@ -1,4 +1,5 @@
 // { dg-options -fwhole-program }
+// { dg-options -fwhole-program -static-libstdc++ { target *-*-mingw* } }

 // Copyright (C) 2011 Free Software Foundation
 //
Index: testsuite/19_diagnostics/error_code/cons/1.cc
===
--- testsuite/19_diagnostics/error_code/cons/1.cc   (Revision 194655)
+++ testsuite/19_diagnostics/error_code/cons/1.cc   (Arbeitskopie)
@@ -1,4 +1,5 @@
 // { dg-options -std=gnu++0x }
+// { dg-options -std=gnu++0x -static-libstdc++ { target *-*-mingw* } }
 // 2007-08-22 Benjamin Kosnik  b...@redhat.com

 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
Index: testsuite/19_diagnostics/error_code/operators/bool.cc
===
--- testsuite/19_diagnostics/error_code/operators/bool.cc   (Revision 
194655)
+++ testsuite/19_diagnostics/error_code/operators/bool.cc   (Arbeitskopie)
@@ -1,4 +1,5 @@
 // { dg-options -std=gnu++0x }
+// { dg-options -std=gnu++0x -static-libstdc++ { target *-*-mingw* } }
 // 2007-08-22 Benjamin Kosnik  b...@redhat.com

 // Copyright (C) 2007, 2009 Free Software Foundation, Inc.
Index: testsuite/19_diagnostics/error_code/operators/equal.cc

Re: [patch libstdc++]: Fix LLP64 pointer-size issues for cxxabi, eh_alloc, and hash_bytes

2012-12-21 Thread Kai Tietz
2012/12/21 Uros Bizjak ubiz...@gmail.com:
 Hello!

 2012-12-21  Kai Tietz

   * config/os/mingw32/os_defines.h (_GLIBCXX_LLP64): Define if llp64
   abi is used.
   * config/os/mingw32-w64/os_defines.h: Likewise.
   * libsupc++/cxxabi.h (__base_class_type_info): Adjust
   type of __offset_flags for llp64.
   * libsupc++/eh_alloc.cc (EMERGENCY_OBJ_SIZE): Define proper
   for llp64 abi.
   (EMERGENCY_OBJ_COUNT): Likewise.
   (bitmask_type): Likewise.
   * ibsupc++/hash_bytes.cc (_Hash_bytes): Handle llp64.

  // { dg-options -fwhole-program }
 +// { dg-options -fwhole-program -static-libstdc++ { target *-*-mingw* } }

 Please use dg-additional-options in these cases.

I tried, but it doesn't seems to be supported by libstdc++'s testsuite.

Kai

PS: Sorry, testsuite cases I wanted sent separately, as I am still
going through it to adjust static-linking.


[patch c++]: Fix type_info struct for llp64 targets

2012-12-21 Thread Kai Tietz
Hello,

this patch fixes the layout of the info_type-s for llp64 target.  We
used here 'long' type instead
of pointer-scalar-witdth type.  That's an issue for llp64 targets.
I introduced for that the LONGPTR_T helper-macro, which has either
scalar-size of 'long' type, or
of 'long long' type's size, if pointer is larger then scalar-size of
'long' type.

ChangeLog

2012-12-21  Kai Tietz

* rtti.c (LONGPTR_T): New helper-macro.
(get_pseudo_ti_init): Initialize offset_type by LONGPTR_T
type instead of 'long' type.
(create_tinfo_types): Use for offset/flags field LONGPTR_T
type instead of 'long' type.

Tested for x86_64-w64-mingw32, i686-w64-mingw32, and
x86_64-unknown-linux-gnu.  Ok for apply?

Regards,
Kai

Index: rtti.c
===
--- rtti.c  (Revision 194660)
+++ rtti.c  (Arbeitskopie)
@@ -89,6 +89,12 @@ typedef enum tinfo_kind
   /* ...  abi::__vmi_type_infoI */
 } tinfo_kind;

+/* Helper macro to get maximum scalar-width of pointer or of the 'long'-type.
+   This of interest for llp64 targets.  */
+#define LONGPTR_T \
+  integer_types[(POINTER_SIZE = TYPE_PRECISION (integer_types[itk_long]) \
+? itk_long : itk_long_long)]
+
 /* A vector of all tinfo decls that haven't yet been emitted.  */
 vectree, va_gc *unemitted_tinfo_decls;

@@ -1116,7 +1122,7 @@ get_pseudo_ti_init (tree type, unsigned tk_index)
tree binfo = TYPE_BINFO (type);
int nbases = BINFO_N_BASE_BINFOS (binfo);
vectree, va_gc *base_accesses = BINFO_BASE_ACCESSES (binfo);
-   tree offset_type = integer_types[itk_long];
+   tree offset_type = LONGPTR_T;
tree base_inits = NULL_TREE;
int ix;
vecconstructor_elt, va_gc *init_vec = NULL;
@@ -1413,14 +1419,15 @@ create_tinfo_types (void)
   /* Base class internal helper. Pointer to base type, offset to base,
  flags.  */
   {
-tree field, fields;
+tree field, fields, offset_flags_type;

 field = build_decl (BUILTINS_LOCATION,
FIELD_DECL, NULL_TREE, type_info_ptr_type);
 fields = field;

+offset_flags_type = LONGPTR_T;
 field = build_decl (BUILTINS_LOCATION,
-   FIELD_DECL, NULL_TREE, integer_types[itk_long]);
+   FIELD_DECL, NULL_TREE, offset_flags_type);
 DECL_CHAIN (field) = fields;
 fields = field;


Re: [patch libstdc++]: Fix LLP64 pointer-size issues for cxxabi, eh_alloc, and hash_bytes

2012-12-21 Thread Kai Tietz
2012/12/21 Gabriel Dos Reis g...@integrable-solutions.net:
 On Fri, Dec 21, 2012 at 3:48 AM, Kai Tietz ktiet...@googlemail.com wrote:
 2012/12/21 Paolo Carlini paolo.carl...@oracle.com:
 On 12/21/2012 10:36 AM, Kai Tietz wrote:

 well, issue isn't that 'long' is always 'ptrdiff_t'.

 But then, if we just change the type without paying attention to size (and
 alignment) aren't we looking for BIG ABI trouble?!?

 Huh?  We have ABI-trouble due long is  too small to hold a
 pointer-diff for llp64.  Intended is here 'pointer-size' AFAICS in
 code, but with wrong assumption that a 'long' is always long enough.

  Btw I just checked all targets we have right now in gcc.  The type
 ptrdiff_t is always either 'long', or 'int' (ilp32, lp64), and 'long
 long' for LLP64.  Means ptrdiff_t gets always equal (or bigger) to
 biggest pointer-size for target (AFAICS).

 Kai

 We must write the codes so that their intents are clear, without
 requiring lot of reverse engineering every time one looks at them.  If we
 intend offset, then clearly ptrdiff_t is the first choice.  Solid
 reasons must be provided why it can't be ptrdiff_t and such
 reasons must be part of the code as comments explaining why
 the obvious thing should be discounted.

 - Gaby

Agreed that we are using at some place too complex logic to avoid
standard-types we already have ...
We need to modify for cxxabi.h header-change also cp/rtti.c, as here
the 'long' type-assumption is done, too.  instead of using
integer_type[itk_long/itk_long_long] there we then have to use instead
ptrdiff_type_node.  And this is for some targets a possible ABI-change
due type_info-record might change size ... for 4.9 this change looks
suitable to me, but for 4.8 we should simply check for now for
itk_long/itk_long_long here (as done by other patch I've sent).

Kai


Re: [patch c++]: Fix type_info struct for llp64 targets

2012-12-27 Thread Kai Tietz
Ping

2012/12/21 Kai Tietz ktiet...@googlemail.com:
 Hello,

 this patch fixes the layout of the info_type-s for llp64 target.  We
 used here 'long' type instead
 of pointer-scalar-witdth type.  That's an issue for llp64 targets.
 I introduced for that the LONGPTR_T helper-macro, which has either
 scalar-size of 'long' type, or
 of 'long long' type's size, if pointer is larger then scalar-size of
 'long' type.

 ChangeLog

 2012-12-21  Kai Tietz

 * rtti.c (LONGPTR_T): New helper-macro.
 (get_pseudo_ti_init): Initialize offset_type by LONGPTR_T
 type instead of 'long' type.
 (create_tinfo_types): Use for offset/flags field LONGPTR_T
 type instead of 'long' type.

 Tested for x86_64-w64-mingw32, i686-w64-mingw32, and
 x86_64-unknown-linux-gnu.  Ok for apply?

 Regards,
 Kai

 Index: rtti.c
 ===
 --- rtti.c  (Revision 194660)
 +++ rtti.c  (Arbeitskopie)
 @@ -89,6 +89,12 @@ typedef enum tinfo_kind
/* ...  abi::__vmi_type_infoI */
  } tinfo_kind;

 +/* Helper macro to get maximum scalar-width of pointer or of the 'long'-type.
 +   This of interest for llp64 targets.  */
 +#define LONGPTR_T \
 +  integer_types[(POINTER_SIZE = TYPE_PRECISION (integer_types[itk_long]) \
 +? itk_long : itk_long_long)]
 +
  /* A vector of all tinfo decls that haven't yet been emitted.  */
  vectree, va_gc *unemitted_tinfo_decls;

 @@ -1116,7 +1122,7 @@ get_pseudo_ti_init (tree type, unsigned tk_index)
 tree binfo = TYPE_BINFO (type);
 int nbases = BINFO_N_BASE_BINFOS (binfo);
 vectree, va_gc *base_accesses = BINFO_BASE_ACCESSES (binfo);
 -   tree offset_type = integer_types[itk_long];
 +   tree offset_type = LONGPTR_T;
 tree base_inits = NULL_TREE;
 int ix;
 vecconstructor_elt, va_gc *init_vec = NULL;
 @@ -1413,14 +1419,15 @@ create_tinfo_types (void)
/* Base class internal helper. Pointer to base type, offset to base,
   flags.  */
{
 -tree field, fields;
 +tree field, fields, offset_flags_type;

  field = build_decl (BUILTINS_LOCATION,
 FIELD_DECL, NULL_TREE, type_info_ptr_type);
  fields = field;

 +offset_flags_type = LONGPTR_T;
  field = build_decl (BUILTINS_LOCATION,
 -   FIELD_DECL, NULL_TREE, integer_types[itk_long]);
 +   FIELD_DECL, NULL_TREE, offset_flags_type);
  DECL_CHAIN (field) = fields;
  fields = field;



-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| ()_() him gain world domination


Re: [PATCH]: Fix for PR 55707 bootstrap fails in gcc/graphite-dependences.c error cast loses precision

2013-01-03 Thread Kai Tietz
Hi Rainer,

applied at rev 194859.

Thanks,
Kai


[patch libbacktrace]: Fix undeclared-symbols warning for SjLj-targets

2013-01-18 Thread Kai Tietz
Hi,

this patch cleans up a undeclared-symbol issue in libbacktrace.
ChangeLog

2013-01-18  Kai Tietz  kti...@redhat.com

* backtrace.c (_Unwind_GetIPInfo): Add prototype.
* simple.c (_Unwind_GetIPInfo): Likewise.

Tested for x86_64-w64-mingw32, and i686-w64-mingw32.  Ok for apply?

Kai

Index: backtrace.c
===
--- backtrace.c (Revision 195288)
+++ backtrace.c (Arbeitskopie)
@@ -55,6 +55,8 @@ struct backtrace_data
   int ret;
 };

+extern uintptr_t _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
+
 /* Unwind library callback routine.  This is passed to
_Unwind_Backtrace.  */

Index: simple.c
===
--- simple.c(Revision 195288)
+++ simple.c(Arbeitskopie)
@@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE.  */
 #include unwind.h
 #include backtrace.h

+extern uintptr_t _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
+
 /* The simple_backtrace routine.  */

 /* Data passed through _Unwind_Backtrace.  */


[patch libstdc++]: Fix tests trying to override symbols in shared-library for mingw targets

2013-01-18 Thread Kai Tietz
Hi,

this patch addresses some of libstdc++'s testsuite regressions on
pe-coff targets due none-overridable symbols in DLL files.
ChangeLog

* 18_support/50594.cc: Force use of static libstdc++ for
mingw targets.
* 19_diagnostics/error_category/operators/equal.cc: Likewise.
* 19_diagnostics/error_code/cons/1.cc: Likewise.
* 19_diagnostics/error_code/operators/bool.cc: Likewise.
* 19_diagnostics/error_code/operators/equal.cc: Likewise.
* 19_diagnostics/error_condition/cons/1.cc: Likewise.
* 19_diagnostics/error_condition/operators/bool.cc: Likewise.
* 19_diagnostics/error_condition/operators/equal.cc: Likewise.
* 19_diagnostics/error_condition/operators/not_equal.cc: Likewise.
* 23_containers/set/requirements/exception/basic.cc: Likewise.
* lib/dg-options.exp (dg-additional-options): Likewise.
* 26_numerics/headers/cmath/c99_classification_macros_c.cc: Add mingw 
targets
as known to fail.

Tested for x86_64-w64-mingw32, i686-w64-mingw32, and
x86_64-unknown-linux-gnu.  Ok for apply?

Regards,
Kai

Index: testsuite/18_support/50594.cc
===
--- testsuite/18_support/50594.cc   (Revision 195288)
+++ testsuite/18_support/50594.cc   (Arbeitskopie)
@@ -1,4 +1,5 @@
 // { dg-options -fwhole-program }
+// { dg-additional-options -static-libstdc++ { target *-*-mingw* } }

 // Copyright (C) 2011 Free Software Foundation
 //
Index: testsuite/19_diagnostics/error_category/operators/equal.cc
===
--- testsuite/19_diagnostics/error_category/operators/equal.cc  (Revision 
195288)
+++ testsuite/19_diagnostics/error_category/operators/equal.cc  (Arbeitskopie)
@@ -1,4 +1,5 @@
 // { dg-options -std=gnu++0x }
+// { dg-additional-options -static-libgcc { target *-*-mingw* } }
 // 2007-08-22 Benjamin Kosnik  b...@redhat.com

 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
Index: testsuite/19_diagnostics/error_code/cons/1.cc
===
--- testsuite/19_diagnostics/error_code/cons/1.cc   (Revision 195288)
+++ testsuite/19_diagnostics/error_code/cons/1.cc   (Arbeitskopie)
@@ -1,4 +1,5 @@
 // { dg-options -std=gnu++0x }
+// { dg-additional-options -static-libstdc++ { target *-*-mingw* } }
 // 2007-08-22 Benjamin Kosnik  b...@redhat.com

 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
Index: testsuite/19_diagnostics/error_code/operators/bool.cc
===
--- testsuite/19_diagnostics/error_code/operators/bool.cc   (Revision 
195288)
+++ testsuite/19_diagnostics/error_code/operators/bool.cc   (Arbeitskopie)
@@ -1,4 +1,5 @@
 // { dg-options -std=gnu++0x }
+// { dg-additional-options -static-libstdc++ { target *-*-mingw* } }
 // 2007-08-22 Benjamin Kosnik  b...@redhat.com

 // Copyright (C) 2007, 2009 Free Software Foundation, Inc.
Index: testsuite/19_diagnostics/error_code/operators/equal.cc
===
--- testsuite/19_diagnostics/error_code/operators/equal.cc  (Revision 
195288)
+++ testsuite/19_diagnostics/error_code/operators/equal.cc  (Arbeitskopie)
@@ -1,4 +1,5 @@
 // { dg-options -std=gnu++0x }
+// { dg-additional-options -static-libstdc++ { target *-*-mingw* } }
 // 2007-08-22 Benjamin Kosnik  b...@redhat.com

 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
Index: testsuite/19_diagnostics/error_code/operators/not_equal.cc
===
--- testsuite/19_diagnostics/error_code/operators/not_equal.cc  (Revision 
195288)
+++ testsuite/19_diagnostics/error_code/operators/not_equal.cc  (Arbeitskopie)
@@ -1,4 +1,5 @@
 // { dg-options -std=gnu++0x }
+// { dg-additional-options -static-libstdc++ { target *-*-mingw* } }
 // 2007-08-22 Benjamin Kosnik  b...@redhat.com

 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
Index: testsuite/19_diagnostics/error_condition/cons/1.cc
===
--- testsuite/19_diagnostics/error_condition/cons/1.cc  (Revision 195288)
+++ testsuite/19_diagnostics/error_condition/cons/1.cc  (Arbeitskopie)
@@ -1,4 +1,5 @@
 // { dg-options -std=gnu++0x }
+// { dg-additional-options -static-libstdc++ { target *-*-mingw* } }

 // Copyright (C) 2008, 2009 Free Software Foundation, Inc.
 //
Index: testsuite/19_diagnostics/error_condition/operators/bool.cc
===
--- testsuite/19_diagnostics/error_condition/operators/bool.cc  (Revision 
195288)
+++ testsuite/19_diagnostics/error_condition/operators/bool.cc  (Arbeitskopie)
@@ -1,4 +1,5 @@
 // { dg-options -std=gnu++0x }
+// { dg-additional-options -static-libstdc++ { target *-*-mingw* } }

 // Copyright (C) 

Re: [patch libbacktrace]: Fix undeclared-symbols warning for SjLj-targets

2013-01-18 Thread Kai Tietz
Sure, it is.  But the point is that system's unwind.h header is used
over the local one.  So if you have an older gcc to build, you might
get the wrong unwind.h header.  I admit that this patch is a kludge
but fixes issue I have with bootstrap cross on cygwin by using a gcc
3.4.4 compiler.

2013/1/18 Jakub Jelinek ja...@redhat.com:
 On Fri, Jan 18, 2013 at 11:05:11AM +0100, Kai Tietz wrote:
 this patch cleans up a undeclared-symbol issue in libbacktrace.

 It is prototyped in unwind.h, at least should be.

 2013-01-18  Kai Tietz  kti...@redhat.com

   * backtrace.c (_Unwind_GetIPInfo): Add prototype.
   * simple.c (_Unwind_GetIPInfo): Likewise.

 Tested for x86_64-w64-mingw32, and i686-w64-mingw32.  Ok for apply?

 Jakub


Re: [patch libstdc++]: Fix tests trying to override symbols in shared-library for mingw targets

2013-01-18 Thread Kai Tietz
2013/1/18 Jonathan Wakely jwakely@gmail.com:
 On 18 January 2013 10:17, Kai Tietz wrote:
 Hi,

 this patch addresses some of libstdc++'s testsuite regressions on
 pe-coff targets due none-overridable symbols in DLL files.
 ChangeLog

 * 18_support/50594.cc: Force use of static libstdc++ for
 mingw targets.
 * 19_diagnostics/error_category/operators/equal.cc: Likewise.
 * 19_diagnostics/error_code/cons/1.cc: Likewise.
 * 19_diagnostics/error_code/operators/bool.cc: Likewise.
 * 19_diagnostics/error_code/operators/equal.cc: Likewise.
 * 19_diagnostics/error_condition/cons/1.cc: Likewise.
 * 19_diagnostics/error_condition/operators/bool.cc: Likewise.
 * 19_diagnostics/error_condition/operators/equal.cc: Likewise.
 * 19_diagnostics/error_condition/operators/not_equal.cc: Likewise.
 * 23_containers/set/requirements/exception/basic.cc: Likewise.
 * lib/dg-options.exp (dg-additional-options): Likewise.
 * 26_numerics/headers/cmath/c99_classification_macros_c.cc: Add 
 mingw targets
 as known to fail.

 Tested for x86_64-w64-mingw32, i686-w64-mingw32, and
 x86_64-unknown-linux-gnu.  Ok for apply?

 Congratulations, you're the first person to touch these files this
 year, so you win the privilege of updating the copyright years!  ;-)

Oh lucky I am, I am winner!  ;)

 (Don't forget that on the trunk now you can replace a series of dates
 like 2008, 2009, 2011 with the range 2008-2013.)

Sure I will modify the copyright-notice of the files I've touched here.

 Index: testsuite/lib/dg-options.exp
 ===
 --- testsuite/lib/dg-options.exp(Revision 195288)
 +++ testsuite/lib/dg-options.exp(Arbeitskopie)
 @@ -219,3 +219,25 @@ proc add_options_for_no_pch { flags } {
  # This forces any generated and possibly included PCH to be invalid.
  return -D__GLIBCXX__=
  }
 +
 +# Like dg-options, but adds to the default options rather than replacing 
 them.
 +
 +proc dg-additional-options { args } {
 +upvar dg-extra-tool-flags extra-tool-flags
 +
 +if { [llength $args]  3 } {
 +error [lindex $args 0]: too many arguments
 +return
 +}
 +
 +if { [llength $args] = 3 } {

 Is this condition right or should it check for exactly three?

Well, I copied stuff from gcc's testsuite.  As we check some lines
about for args  3 and error out, a test for == 3 makes sense, but
well, = 3 is fine too.

 +switch [dg-process-target [lindex $args 2]] {
 +S { eval lappend extra-tool-flags [lindex $args 1] }
 +N { }
 +F { error [lindex $args 0]: `xfail' not allowed here }
 +P { error [lindex $args 0]: `xfail' not allowed here }
 +}
 +} else {
 +eval lappend extra-tool-flags [lindex $args 1]
 +}
 +}


[patch libiberty's include]: Fixes PR 39064 and partial PR 54620

2013-01-30 Thread Kai Tietz
Hi,

this patch fixes for targets with sys/types.h the issue that wrong
assumptions about pointer-sizes are used.
Instead it uses uintptr_t/intptr_t.

ChangeLog /include

2013-01-30  Kai Tietz  kti...@redhat.com

PR other/54620
PR target/39064
* md5.h: Include sys/types.h if HAVE_SYS_TYPES_H
is defined.
* sha1.h: Likewise.

Tested for x86_64-unknown-linux-gnu, x86_64-w64-mingw32, and
i686-w64-mingw32.  Ok for apply?

Regards,
Kai

Index: md5.h
===
--- md5.h   (Revision 195288)
+++ md5.h   (Arbeitskopie)
@@ -36,7 +36,7 @@
the resulting executable.  Locally running cross-compiled executables
is usually not possible.  */

-#ifdef _LIBC
+#if defined (_LIBC) || defined (HAVE_SYS_TYPES_H)
 # include sys/types.h
 typedef u_int32_t md5_uint32;
 typedef uintptr_t md5_uintptr;
Index: sha1.h
===
--- sha1.h  (Revision 195288)
+++ sha1.h  (Arbeitskopie)
@@ -35,7 +35,7 @@
the resulting executable.  Locally running cross-compiled executables
is usually not possible.  */

-#ifdef _LIBC
+#if defined (_LIBC) || defined (HAVE_SYS_TYPES_H)
 # include sys/types.h
 typedef u_int32_t sha1_uint32;
 typedef uintptr_t sha1_uintptr;


Re: [patch libiberty's include]: Fixes PR 39064 and partial PR 54620

2013-01-30 Thread Kai Tietz
2013/1/30 Ian Lance Taylor i...@google.com:
 On Wed, Jan 30, 2013 at 2:53 AM, Kai Tietz ktiet...@googlemail.com wrote:

 this patch fixes for targets with sys/types.h the issue that wrong
 assumptions about pointer-sizes are used.
 Instead it uses uintptr_t/intptr_t.

 ChangeLog /include

 2013-01-30  Kai Tietz  kti...@redhat.com

 PR other/54620
 PR target/39064
 * md5.h: Include sys/types.h if HAVE_SYS_TYPES_H
 is defined.
 * sha1.h: Likewise.

 Tested for x86_64-unknown-linux-gnu, x86_64-w64-mingw32, and
 i686-w64-mingw32.  Ok for apply?

 Regards,
 Kai

 Index: md5.h
 ===
 --- md5.h   (Revision 195288)
 +++ md5.h   (Arbeitskopie)
 @@ -36,7 +36,7 @@
 the resulting executable.  Locally running cross-compiled executables
 is usually not possible.  */

 -#ifdef _LIBC
 +#if defined (_LIBC) || defined (HAVE_SYS_TYPES_H)
  # include sys/types.h
  typedef u_int32_t md5_uint32;
  typedef uintptr_t md5_uintptr;
 Index: sha1.h
 ===
 --- sha1.h  (Revision 195288)
 +++ sha1.h  (Arbeitskopie)
 @@ -35,7 +35,7 @@
 the resulting executable.  Locally running cross-compiled executables
 is usually not possible.  */

 -#ifdef _LIBC
 +#if defined (_LIBC) || defined (HAVE_SYS_TYPES_H)
  # include sys/types.h
  typedef u_int32_t sha1_uint32;
  typedef uintptr_t sha1_uintptr;



 This code is intended to be highly portable.  I don't have a problem
 with uintptr_t, but I'm not certain that sys/types.h on all systems
 defines u_int32_t.

 Ian

Yes, this is a valid point.  The (u)int??_t types aren't necessarily
declared by including sys/types.h.  So what's about the following
patch.  If stdint.h header is present, then we should include it and
then we can assume that the (u)int??_t types are present.

Index: md5.h
===
--- md5.h   (Revision 195572)
+++ md5.h   (Arbeitskopie)
@@ -36,7 +36,11 @@
the resulting executable.  Locally running cross-compiled executables
is usually not possible.  */

-#ifdef _LIBC
+#ifdef HAVE_STDINT_H
+#include stdint.h
+#endif
+
+#if defined (_LIBC) || (defined (HAVE_SYS_TYPES_H)  defined (HAVE_STDINT_H))
 # include sys/types.h
 typedef u_int32_t md5_uint32;
 typedef uintptr_t md5_uintptr;
Index: sha1.h
===
--- sha1.h  (Revision 195572)
+++ sha1.h  (Arbeitskopie)
@@ -35,7 +35,11 @@
the resulting executable.  Locally running cross-compiled executables
is usually not possible.  */

-#ifdef _LIBC
+#ifdef HAVE_STDINT_H
+#include stdint.h
+#endif
+
+#if defined (_LIBC) || (defined (HAVE_SYS_TYPES_H)  defined (HAVE_STDINT_H))
 # include sys/types.h
 typedef u_int32_t sha1_uint32;
 typedef uintptr_t sha1_uintptr;


Re: [patch libiberty's include]: Fixes PR 39064 and partial PR 54620

2013-01-30 Thread Kai Tietz
Hmm, I see ...  so we need an new condition.

Is it ok to apply?

Thanks,
Kai

Index: md5.h
===
--- md5.h   (Revision 195572)
+++ md5.h   (Arbeitskopie)
@@ -40,6 +40,11 @@
 # include sys/types.h
 typedef u_int32_t md5_uint32;
 typedef uintptr_t md5_uintptr;
+#elif defined (HAVE_SYS_TYPES_H)  defined (HAVE_STDINT_H)
+#include stdint.h
+#include sys/types.h
+typedef uint32_t md5_uint32;
+typedef uintptr_t md5_uintptr;
 #else
 #  define INT_MAX_32_BITS 2147483647

Index: sha1.h
===
--- sha1.h  (Revision 195572)
+++ sha1.h  (Arbeitskopie)
@@ -39,6 +39,11 @@
 # include sys/types.h
 typedef u_int32_t sha1_uint32;
 typedef uintptr_t sha1_uintptr;
+#elif defined (HAVE_SYS_TYPES_H)  defined (HAVE_STDINT_H)
+#include stdint.h
+#include sys/types.h
+typedef uint32_t sha1_uint32;
+typedef uintptr_t sha1_uintptr;
 #else
 #  define INT_MAX_32_BITS 2147483647


[patch libiberty]: Fix PR 54620

2013-01-30 Thread Kai Tietz
Hi,

this patch fixes wrong handling of cases that bitness of size_t is
wider as 32-bit.

ChangeLog

2013-01-30  Kai Tietz  kti...@redhat.com

PR other/54620
* sha1.c (sha1_process_block):  Handle case that size_t is
a wider-integer-scalar as a 32-bit unsigned integer.

Tested for x86_64-unknown-linux-gnu, i686-pc-cygwin, and
x86_64-w64-mingw32.  Ok for apply?

Regards,
Kai

Index: sha1.c
===
--- sha1.c  (Revision 195578)
+++ sha1.c  (Arbeitskopie)
@@ -300,8 +300,7 @@ sha1_process_block (const void *buffer, size_t len
  length of the file up to 2^64 bits.  Here we only compute the
  number of bytes.  Do a double word increment.  */
   ctx-total[0] += len;
-  if (ctx-total[0]  len)
-++ctx-total[1];
+  ctx-total[1] += ((len  31)  1) + (ctx-total[0]  len);

 #define rol(x, n) (((x)  (n)) | ((sha1_uint32) (x)  (32 - (n


[patch libiberty]: Fix PR 53285 on 4.7 branch

2013-01-30 Thread Kai Tietz
Hi,

this patch backports a fix from trunk
ChangeLog

2013-01-30  Kai Tietz  kti...@redhat.com
2012-07-31  Mike Frysinger  vap...@gentoo.org

Merged from trunk.
PR other/53285
* md5.c (md5_finish_ctx): Declare swap_bytes.  Assign SWAP() output
to swap_bytes, and then call memcpy to move it to ctx-buffer.

Tested for x86_64-unknown-linux-gnu, i686-w64-mingw32, and
i686-pc-cygwin.  Ok for apply?

Regards,
Kai

Index: md5.c
===
--- md5.c   (Revision 194858)
+++ md5.c   (Arbeitskopie)
@@ -103,6 +103,7 @@ md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
 {
   /* Take yet unprocessed bytes into account.  */
   md5_uint32 bytes = ctx-buflen;
+  md5_uint32 swap_bytes;
   size_t pad;

   /* Now count remaining bytes.  */
@@ -113,10 +114,13 @@ md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
   pad = bytes = 56 ? 64 + 56 - bytes : 56 - bytes;
   memcpy (ctx-buffer[bytes], fillbuf, pad);

-  /* Put the 64-bit file length in *bits* at the end of the buffer.  */
-  *(md5_uint32 *) ctx-buffer[bytes + pad] = SWAP (ctx-total[0]  3);
-  *(md5_uint32 *) ctx-buffer[bytes + pad + 4] = SWAP ((ctx-total[1]  3) |
-   (ctx-total[0]  29));
+  /* Put the 64-bit file length in *bits* at the end of the buffer.
+ Use memcpy to avoid aliasing problems.  On most systems, this
+ will be optimized away to the same code.  */
+  swap_bytes = SWAP (ctx-total[0]  3);
+  memcpy (ctx-buffer[bytes + pad], swap_bytes, sizeof (swap_bytes));
+  swap_bytes = SWAP ((ctx-total[1]  3) | (ctx-total[0]  29));
+  memcpy (ctx-buffer[bytes + pad + 4], swap_bytes, sizeof (swap_bytes));

   /* Process last bytes.  */
   md5_process_block (ctx-buffer, bytes + pad + 8, ctx);


[patch i386]: Fix PR target/56186

2013-02-04 Thread Kai Tietz
Hello,

this patch fixes reported regression about 128-bit return-type for x64 ABI.

ChangeLog 2013-02-04  Kai Tietz  kti...@redhat.com

PR target/56186
* i386.c (function_value_64): Add additional valtype argument
and improve checking of return-argument types for 16-byte modes.
(ix86_function_value_1): Add additional valtype argument on call
of function_value_64.
(return_in_memory_ms_64): Sync 16-byte sized mode handling with
handling infunction_value_64 function.

Tested for x86_64-w64-mingw32, and for x86_64-unknown-linux-gnu.  Ok for apply?

Regards,
Kai

Index: i386.c
===
--- i386.c  (Revision 195572)
+++ i386.c  (Arbeitskopie)
@@ -7324,7 +7324,8 @@ function_value_64 (enum machine_mode orig_mode, en
 }

 static rtx
-function_value_ms_64 (enum machine_mode orig_mode, enum machine_mode mode)
+function_value_ms_64 (enum machine_mode orig_mode, enum machine_mode mode,
+ const_tree valtype)
 {
   unsigned int regno = AX_REG;

@@ -7333,6 +7334,12 @@ static rtx
   switch (GET_MODE_SIZE (mode))
 {
 case 16:
+ if (valtype != NULL_TREE
+  !VECTOR_INTEGER_TYPE_P (valtype)
+   !VECTOR_INTEGER_TYPE_P (valtype)
+  !INTEGRAL_TYPE_P (valtype)
+  !VECTOR_FLOAT_TYPE_P (valtype))
+   break;
   if((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
  !COMPLEX_MODE_P (mode))
regno = FIRST_SSE_REG;
@@ -7361,7 +7368,7 @@ ix86_function_value_1 (const_tree valtype, const_t
   fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;

   if (TARGET_64BIT  ix86_function_type_abi (fntype) == MS_ABI)
-return function_value_ms_64 (orig_mode, mode);
+return function_value_ms_64 (orig_mode, mode, valtype);
   else if (TARGET_64BIT)
 return function_value_64 (orig_mode, mode, valtype);
   else
@@ -7474,7 +7481,9 @@ return_in_memory_ms_64 (const_tree type, enum mach
   HOST_WIDE_INT size = int_size_in_bytes (type);

   /* __m128 is returned in xmm0.  */
-  if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
+  if ((!type || VECTOR_INTEGER_TYPE_P (type) || INTEGRAL_TYPE_P (type)
+   || VECTOR_FLOAT_TYPE_P (type))
+   (SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
!COMPLEX_MODE_P (mode)  (GET_MODE_SIZE (mode) == 16 || size == 16))
 return false;


Re: [patch i386]: Fix PR target/56186

2013-02-04 Thread Kai Tietz
2013/2/4 Jakub Jelinek ja...@redhat.com:
 On Mon, Feb 04, 2013 at 02:38:23PM +0100, Kai Tietz wrote:
 Tested for x86_64-w64-mingw32, and for x86_64-unknown-linux-gnu.  Ok for 
 apply?

 Please make sure to also test with a 4.7 based compiler (assuming
 it is gcc47 and g++47) using
 make check ALT_CC_UNDER_TEST=gcc47 ALT_CXX_UNDER_TEST=g++47 
 RUNTESTFLAGS='compat.exp struct-layout-1.exp'


 Index: i386.c
 ===
 --- i386.c(Revision 195572)
 +++ i386.c(Arbeitskopie)
 @@ -7324,7 +7324,8 @@ function_value_64 (enum machine_mode orig_mode, en
  }

  static rtx
 -function_value_ms_64 (enum machine_mode orig_mode, enum machine_mode mode)
 +function_value_ms_64 (enum machine_mode orig_mode, enum machine_mode mode,
 +   const_tree valtype)
  {
unsigned int regno = AX_REG;

 @@ -7333,6 +7334,12 @@ static rtx
switch (GET_MODE_SIZE (mode))
  {
  case 16:
 +   if (valtype != NULL_TREE
 +!VECTOR_INTEGER_TYPE_P (valtype)
 +   !VECTOR_INTEGER_TYPE_P (valtype)

 Wrong whitespace above (spaces instead of tabs)?

 +!INTEGRAL_TYPE_P (valtype)
 +!VECTOR_FLOAT_TYPE_P (valtype))
 + break;
if((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
 !COMPLEX_MODE_P (mode))
   regno = FIRST_SSE_REG;

 Jakub

I corrected this in applied patch.  There were before spaces used
instead of tab.

Thanks for noticing it.

Kai


Re: [PATCH] Port Jason's r195550 varasm.c change also to mingw/cygwin/solaris private copies (PR libstdc++/54314)

2013-02-04 Thread Kai Tietz
2013/2/4 Jakub Jelinek ja...@redhat.com:
 Hi!

 In http://gcc.gnu.org/viewcvs?root=gccview=revrev=195550
 Jason changed the default assemble_visibility target hook to avoid
 complaining on DECL_ARTIFICIAL decls, even when they have some visibility
 set (the C++ FE now sets visibility of construction vtables), this patch
 ports that to solaris and winnt private variants of the hook.

 Tested with Solaris cross on the testcase, ok for trunk?

 2013-02-04  Jakub Jelinek  ja...@redhat.com
 PR libstdc++/54314
 * config/i386/winnt.c (i386_pe_assemble_visibility): Don't warn
 about visibility on artificial decls.

The mingw-part is ok.

Thanks,
Kai


[patch libada]: PR target/52122

2013-02-06 Thread Kai Tietz
Hi,

this patch fixes an issue about recursice LN_S for mingw-host.  The
issue was already addressed by autotools, but an upgrade of version
isn't suitable right now.
For further information see the bug-report PR 52122.

ChangeLog libada/

PR target/52122
* Makefile.in (LN_S_RECUSIVE): New.
(adainclude, adalib): Use LN_S_RECURSIVE for copy.

Patch see at http://gcc.gnu.org/bugzilla/attachment.cgi?id=29176

Ok for apply?

Regards,
Kai


Re: [PATCH, bootstrap]: Fix PR56227, bootstrap failure on MinGW.

2013-02-07 Thread Kai Tietz
2013/2/7 Uros Bizjak ubiz...@gmail.com:
 Hello!

 Attached (trivial) patch substitutes a bunch of ll conversion types
 with HOST_LONG_LONG_FORMAT defines. Additionally, it fixes wrong usage
 of HOST_WIDE_INT_PRINT_HEX_PURE in the argument of internal_error.

 The patch reportedly fixes bootstrap failures on i686-pc-mingw32.

 2013-02-07  Uros Bizjak  ubiz...@gmail.com

 * ggc-page.c (ggc_print_statistics): Use HOST_LONG_LONG_FORMAT
 instead of ll.
 * config/i386/i386.c (ix86_print_operand): Ditto.

 lto/ChangeLog:

 2013-02-07  Uros Bizjak  ubiz...@gmail.com

 * lto.c (lto_resolution_ready): Use %wx instead of
 HOST_WIDE_INT_PRINT_HEX_PURE in the argument to internal_error.

 Bootstrapped on x86_64-pc-linux-gnu.

 OK for mainline and 4.7 branch?

 Uros.

I have no objections.

Thanks,
Kai


Re: [patch libiberty include]: Add additional helper functions for directory-separator searching

2011-03-08 Thread Kai Tietz
2011/3/8 Eli Zaretskii e...@gnu.org:
 Date: Tue, 8 Mar 2011 11:56:45 +0100
 From: Kai Tietz ktiet...@googlemail.com

 +@deftypefn Extension int filename_dirchr (const char *@var{p})
 +
 +The returned value is similar to what @code{strchr} would return for
 +searching for a directory separator.
 +
 +This function does not normalize file name.  However, it does handle
 +the fact that on DOS-like file systems, forward and backward slashes
 +are directory separators.

 This is very mysterious.  The documentation should explain how this is
 handled, or else the user will have no choice but to look in the
 sources.  And description by similarity doesn't help, because this
 function is obviously different from strchr in _some_ ways, but you
 don't say how.

 While at that, explain the problem this solves, or else the raison
 d'etre of this function will not be understood.  We do want this
 function to be used instead of just strchr, don't we?  For it to be
 used, its purpose and advantages should be well understood.

 Btw, why do we need filename_dirchr?  The use case for
 filename_dirrchr is clear, but in what situations will we need the
 other one?

As the comment notes. strchr/strrchr searches for one character. This
is for unix-file-system normally slash. On DOS based file-systems
there are two characters representing a directory-separator. Slash and
Backslash. Therefore this routine takes care that both are handled
similiar to a single character searching.

 +  if (!r || (r2  r2  r))

 Why do you test for r2 being non-NULL?  You are not going to
 dereference it in the next comparison, and NULL is comparable as any
 other value.

As if we found slash, we don't want to override function's result by
backslash not found. If the null-check wouldn't be present condition
would be always true for r2 == NULL as, NULL is always less then a
pointer. But r shall be modified only if r2 (backslash) was found
before r (slash).
(same logic but here from right to left for the strrchr-case)

Regards,
Kai


Re: [patch libiberty include]: Add additional helper functions for directory-separator searching

2011-03-08 Thread Kai Tietz
2011/3/8 Pedro Alves pe...@codesourcery.com:
 On Tuesday 08 March 2011 12:48:11, Kai Tietz wrote:

 Well, a better example is elfstab_offset_sections() in elfread.c.

  /* The ELF symbol info doesn't include path names, so strip the path
     (if any) from the psymtab filename.  */
  while (0 != (p = strchr (filename, '/')))
    filename = p + 1;

 Looks like its looking for the last path separator, so
 it might as well use filename_dirrchr instead.

True, see patch I've posted about filename_cmp. I replaced it there by
a strrchr search.

 Another is in find_file_and_directory() in dwarf2read.c file.

 Workaround for Irix.  Certainly that '/' should not depend
 on the host gdb is running on.

Right. But well, I was asked if strchr is used in combination with
paths. And so I've shown. If those uses could be rewritten is a
different story and might be true.

Kai


[patch libcpp]: Improve handling of DOS-filenames and -paths

2011-03-14 Thread Kai Tietz
Hello,

this patch fixes some DOS-filename comparision and directory-separator checks.

Changelog libcpp

2011-03-14  Kai Tietz

* files.c (file_hash_eq): Use filename_cmp
instead of strcmp.
(nonexistent_file_hash_eq): Likewise.
(remap_filename): Likewise.
Handle absolute DOS-path,
(append_file_to_dir): Check for IS_DIR_SEPARATOR
instead of slash.
(read_name_map): Likewise.
* linemap.c (linemap_add): Use filename_cmp
instead of strcmp.
* mkdeps.c (apply_vpath): Use filename_ncmp
instead of strncmp.
(deps_restore): Use filename_cmp instead of
strcmp.
* init.c (read_original_directory): Use
IS_DIR_SEPARATOR instead of checking for slash.

Tested for x86_64-pc-linux-gnu and x86_64-w64-mingw32. Ok for apply?

Regards,
Kai
Index: gcc/libcpp/files.c
===
--- gcc.orig/libcpp/files.c 2011-03-14 17:28:34.106392100 +0100
+++ gcc/libcpp/files.c  2011-03-14 18:03:04.260379100 +0100
@@ -1155,7 +1155,7 @@ file_hash_eq (const void *p, const void
   else
 hname = entry-u.dir-name;
 
-  return strcmp (hname, fname) == 0;
+  return filename_cmp (hname, fname) == 0;
 }
 
 /* Compare entries in the nonexistent file hash table.  These are just
@@ -1163,7 +1163,7 @@ file_hash_eq (const void *p, const void
 static int
 nonexistent_file_hash_eq (const void *p, const void *q)
 {
-  return strcmp ((const char *) p, (const char *) q) == 0;
+  return filename_cmp ((const char *) p, (const char *) q) == 0;
 }
 
 /* Initialize everything in this source file.  */
@@ -1413,7 +1413,7 @@ append_file_to_dir (const char *fname, c
   flen = strlen (fname);
   path = XNEWVEC (char, dlen + 1 + flen + 1);
   memcpy (path, dir-name, dlen);
-  if (dlen  path[dlen - 1] != '/')
+  if (dlen  !IS_DIR_SEPARATOR (path[dlen - 1]))
 path[dlen++] = '/';
   memcpy (path[dlen], fname, flen + 1);
 
@@ -1461,7 +1461,7 @@ read_name_map (cpp_dir *dir)
   len = dir-len;
   name = (char *) alloca (len + sizeof (FILE_NAME_MAP_FILE) + 1);
   memcpy (name, dir-name, len);
-  if (len  name[len - 1] != '/')
+  if (len  !IS_DIR_SEPARATOR (name[len - 1]))
 name[len++] = '/';
   strcpy (name + len, FILE_NAME_MAP_FILE);
   f = fopen (name, r);
@@ -1532,10 +1532,18 @@ remap_filename (cpp_reader *pfile, _cpp_
read_name_map (dir);
 
   for (index = 0; dir-name_map[index]; index += 2)
-   if (!strcmp (dir-name_map[index], fname))
+   if (!filename_cmp (dir-name_map[index], fname))
return xstrdup (dir-name_map[index + 1]);
-
+  if (IS_ABSOLUTE_PATH (fname))
+   return NULL;
   p = strchr (fname, '/');
+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
+  {
+   char *p2 = strchr (fname, '\\');
+   if (!p || (p  p2))
+ p = p2;
+  }
+#endif
   if (!p || p == fname)
return NULL;
 
Index: gcc/libcpp/line-map.c
===
--- gcc.orig/libcpp/line-map.c  2011-03-14 17:28:34.108392100 +0100
+++ gcc/libcpp/line-map.c   2011-03-14 18:03:04.274380900 +0100
@@ -138,7 +138,7 @@ linemap_add (struct line_maps *set, enum
   else
{
  from = INCLUDED_FROM (set, map - 1);
- error = to_file  strcmp (from-to_file, to_file);
+ error = to_file  filename_cmp (from-to_file, to_file);
}
 
   /* Depending upon whether we are handling preprocessed input or
Index: gcc/libcpp/mkdeps.c
===
--- gcc.orig/libcpp/mkdeps.c2011-03-14 17:28:34.114392100 +0100
+++ gcc/libcpp/mkdeps.c 2011-03-14 18:03:04.278881500 +0100
@@ -130,7 +130,7 @@ apply_vpath (struct deps *d, const char
   unsigned int i;
   for (i = 0; i  d-nvpaths; i++)
{
- if (!strncmp (d-vpathv[i], t, d-vpathlv[i]))
+ if (!filename_ncmp (d-vpathv[i], t, d-vpathlv[i]))
{
  const char *p = t + d-vpathlv[i];
  if (!IS_DIR_SEPARATOR (*p))
@@ -421,7 +421,7 @@ deps_restore (struct deps *deps, FILE *f
   buf[num_to_read] = '\0';
 
   /* Generate makefile dependencies from .pch if -nopch-deps.  */
-  if (self != NULL  strcmp (buf, self) != 0)
+  if (self != NULL  filename_cmp (buf, self) != 0)
 deps_add_dep (deps, buf);
 }
 
Index: gcc/libcpp/init.c
===
--- gcc.orig/libcpp/init.c  2011-03-14 17:28:34.107392100 +0100
+++ gcc/libcpp/init.c   2011-03-14 18:03:04.283882100 +0100
@@ -26,6 +26,7 @@ along with this program; see the file CO
 #include internal.h
 #include mkdeps.h
 #include localedir.h
+#include filenames.h
 
 static void init_library (void);
 static void mark_named_operators (cpp_reader *, int);
@@ -640,8 +641,8 @@ read_original_directory (cpp_reader *pfi
 
   if (token-type != CPP_STRING
   || ! (token-val.str.len = 5
-token

Re: [patch gcc c++ c-family java fortan lto]: Fix DOS-filesystem issues

2011-03-15 Thread Kai Tietz
2011/3/15 Pedro Alves pe...@codesourcery.com:
 Thanks.

 This looks like lbasename-able as well, getting rid of
 that HAVE_DOS...-ish foo:

Thanks. Yes, that one I missed.

Attached updated version of patch.

Kai
Index: gcc/gcc/c-family/c-ada-spec.c
===
--- gcc.orig/gcc/c-family/c-ada-spec.c  2011-03-14 18:45:20.566392100 +0100
+++ gcc/gcc/c-family/c-ada-spec.c   2011-03-14 20:22:19.023299300 +0100
@@ -559,7 +559,8 @@ compare_comment (const void *lp, const v
   const cpp_comment *rhs = (const cpp_comment *) rp;
 
   if (LOCATION_FILE (lhs-sloc) != LOCATION_FILE (rhs-sloc))
-return strcmp (LOCATION_FILE (lhs-sloc), LOCATION_FILE (rhs-sloc));
+return filename_cmp (LOCATION_FILE (lhs-sloc),
+LOCATION_FILE (rhs-sloc));
 
   if (LOCATION_LINE (lhs-sloc) != LOCATION_LINE (rhs-sloc))
 return LOCATION_LINE (lhs-sloc) - LOCATION_LINE (rhs-sloc);
Index: gcc/gcc/collect2.c
===
--- gcc.orig/gcc/collect2.c 2011-03-14 18:45:20.567392100 +0100
+++ gcc/gcc/collect2.c  2011-03-15 07:57:54.540718100 +0100
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.
 #include system.h
 #include coretypes.h
 #include tm.h
+#include filenames.h
 
 /* TARGET_64BIT may be defined to use driver specific functionality. */
 #undef TARGET_64BIT
@@ -2314,12 +2315,8 @@ write_c_file_stat (FILE *stream, const c
   int frames = (frame_tables.number  0);
 
   /* Figure out name of output_file, stripping off .so version.  */
-  p = strrchr (output_file, '/');
-  if (p == 0)
-p = output_file;
-  else
-p++;
-  q = p;
+  q = p = lbasename (output_file);
+
   while (q)
 {
   q = strchr (q,'.');
@@ -2330,7 +2327,7 @@ write_c_file_stat (FILE *stream, const c
}
   else
{
- if (strncmp (q, SHLIB_SUFFIX, strlen (SHLIB_SUFFIX)) == 0)
+ if (filename_ncmp (q, SHLIB_SUFFIX, strlen (SHLIB_SUFFIX)) == 0)
{
  q += strlen (SHLIB_SUFFIX);
  break;
@@ -3192,10 +3189,10 @@ resolve_lib_name (const char *name)
   for (; list; list = list-next)
{
  /* The following lines are needed because path_prefix list
-may contain directories both with trailing '/' and
+may contain directories both with trailing DIR_SEPARATOR and
 without it.  */
  const char *p = ;
- if (list-prefix[strlen(list-prefix)-1] != '/')
+ if (!IS_DIR_SEPARATOR (list-prefix[strlen(list-prefix)-1]))
p = /;
  for (j = 0; j  2; j++)
{
Index: gcc/gcc/coverage.c
===
--- gcc.orig/gcc/coverage.c 2011-03-14 18:45:20.569392100 +0100
+++ gcc/gcc/coverage.c  2011-03-14 18:45:52.497503800 +0100
@@ -49,6 +49,7 @@ along with GCC; see the file COPYING3.
 #include tree-pass.h
 #include diagnostic-core.h
 #include intl.h
+#include filenames.h
 
 #include gcov-io.c
 
@@ -982,7 +983,7 @@ coverage_init (const char *filename)
   /* + 1 for extra '/', in case prefix doesn't end with /.  */
   int prefix_len;
 
-  if (profile_data_prefix == 0  filename[0] != '/')
+  if (profile_data_prefix == 0  !IS_ABSOLUTE_PATH(filename[0]))
 profile_data_prefix = getpwd ();
 
   prefix_len = (profile_data_prefix) ? strlen (profile_data_prefix) + 1 : 0;
Index: gcc/gcc/fortran/scanner.c
===
--- gcc.orig/gcc/fortran/scanner.c  2011-03-14 18:45:20.588392100 +0100
+++ gcc/gcc/fortran/scanner.c   2011-03-14 18:45:52.506505000 +0100
@@ -1754,7 +1754,7 @@ preprocessor_line (gfc_char_t *c)
   if (flag[2]) /* Ending current file.  */
 {
   if (!current_file-up
- || strcmp (current_file-up-filename, filename) != 0)
+ || filename_cmp (current_file-up-filename, filename) != 0)
{
  gfc_warning_now (%s:%d: file %s left but not entered,
   current_file-filename, current_file-line,
@@ -1774,7 +1774,7 @@ preprocessor_line (gfc_char_t *c)
   /* The name of the file can be a temporary file produced by
  cpp. Replace the name if it is different.  */
 
-  if (strcmp (current_file-filename, filename) != 0)
+  if (filename_cmp (current_file-filename, filename) != 0)
 {
/* FIXME: we leak the old filename because a pointer to it may be stored
   in the linemap.  Alternative could be using GC or updating linemap to
@@ -1891,7 +1891,7 @@ load_file (const char *realfilename, con
   filename = displayedname ? displayedname : realfilename;
 
   for (f = current_file; f; f = f-up)
-if (strcmp (filename, f-filename) == 0)
+if (filename_cmp (filename, f-filename) == 0)
   {
fprintf (stderr, %s:%d: Error: File '%s' is being included 
 recursively\n, current_file-filename, current_file-line,
Index: gcc/gcc/gcc.c

Re: [patch i386,c,c++]: PR/12171 - calling convention omitted in error message

2011-03-17 Thread Kai Tietz
PING, ok for 4.7?

2011/1/4 Jason Merrill ja...@redhat.com:
 On 01/01/2011 01:07 PM, Kai Tietz wrote:

 Well, as here no further agreement was found, I post here the
 alternative suggested by Joseph. I am open-minded which approach will
 be chosen. I just want to fix this long pending issue.
 I split up this patch in two parts. The first simply extends the
 struct attribute_spec by new member 'on_diagnostic' and extends the
 the uses of this structure by this new field. This new member
 specifies if the attribute shall be show on diagnostic output, or not.

 This seems like a reasonable approach, but I'd prefer to describe/name the
 field as indicating that the attribute affects type compatibility (since
 that's why we want to see the attribute in diagnostics), and making the
 default comp_type_attributes use that information.

 Jason




-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| ()_() him gain world domination


Re: [patch i386,c,c++]: PR/12171 - calling convention omitted in error message

2011-03-17 Thread Kai Tietz
2011/3/17 Jason Merrill ja...@redhat.com:
 On 03/17/2011 04:46 AM, Kai Tietz wrote:

 PING, ok for 4.7?

 Did you have a response to my comment below?

 2011/1/4 Jason Merrillja...@redhat.com:

 On 01/01/2011 01:07 PM, Kai Tietz wrote:

 Well, as here no further agreement was found, I post here the
 alternative suggested by Joseph. I am open-minded which approach will
 be chosen. I just want to fix this long pending issue.
 I split up this patch in two parts. The first simply extends the
 struct attribute_spec by new member 'on_diagnostic' and extends the
 the uses of this structure by this new field. This new member
 specifies if the attribute shall be show on diagnostic output, or not.

 This seems like a reasonable approach, but I'd prefer to describe/name
 the
 field as indicating that the attribute affects type compatibility (since
 that's why we want to see the attribute in diagnostics), and making the
 default comp_type_attributes use that information.



I thought to use here instead of on_diagnostic (which is IMHO fine too
as it indicates for now only that attribute shall be displayed on
diagnostics) affects_abi. I think it makes sense to keep that name
as short as possible.

Regards,
Kai


Re: [patch i386,c,c++]: PR/12171 - calling convention omitted in error message

2011-03-17 Thread Kai Tietz
2011/3/17 Jason Merrill ja...@redhat.com:
 On 03/17/2011 12:08 PM, Kai Tietz wrote:

 I thought to use here instead of on_diagnostic (which is IMHO fine too
 as it indicates for now only that attribute shall be displayed on
 diagnostics) affects_abi. I think it makes sense to keep that name
 as short as possible.

 Hmm, type compatibility is higher level than the ABI; it affects whether two
 declarations are considered to be the same.  I think clarity is more
 important than a short name for something that shouldn't be used in that
 many places.  I'd prefer affects_type_identity.

I will update the patch and using this name

 And does changing comp_type_attributes to check it make sense to you?

Well, in general it would, but not all of those affecting type
identity in 64-bit vs. 32-bit case. Most of them affect type identity
only in 32-bit, but not for 64-bit )at least so for amd64/x86). So I
don't think we will profit here much.


Kai


Re: [patch i386,c,c++]: PR/12171 - calling convention omitted in error message

2011-03-21 Thread Kai Tietz
2011/3/18 Jason Merrill ja...@redhat.com:
 OK.

 Jason


Applied first part at rev. 171209. Second part at rev. 171210.

Kai


Re: [patch libcpp]: Improve handling of DOS-filenames and -paths

2011-03-21 Thread Kai Tietz
PING

2011/3/14 Kai Tietz ktiet...@googlemail.com:
 Hello,

 this patch fixes some DOS-filename comparision and directory-separator checks.

 Changelog libcpp

 2011-03-14  Kai Tietz

        * files.c (file_hash_eq): Use filename_cmp
        instead of strcmp.
        (nonexistent_file_hash_eq): Likewise.
        (remap_filename): Likewise.
        Handle absolute DOS-path,
        (append_file_to_dir): Check for IS_DIR_SEPARATOR
        instead of slash.
        (read_name_map): Likewise.
        * linemap.c (linemap_add): Use filename_cmp
        instead of strcmp.
        * mkdeps.c (apply_vpath): Use filename_ncmp
        instead of strncmp.
        (deps_restore): Use filename_cmp instead of
        strcmp.
        * init.c (read_original_directory): Use
        IS_DIR_SEPARATOR instead of checking for slash.

 Tested for x86_64-pc-linux-gnu and x86_64-w64-mingw32. Ok for apply?

 Regards,
 Kai




-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| ()_() him gain world domination


Re: Fix typo on cygming.h

2011-03-22 Thread Kai Tietz
2011/3/22 Nick Clifton ni...@redhat.com:
 Hi Guys,

  I am applying the patch below as an obvious fix.  The definition of
  SUBTARGET_OVERRIDE_OPTIONS in the i386/cygming.h header file has a
  trailing backslash at the end of the macro, leading it to include the
  line that follows.  Fortunately that line is blank, but could change
  one day, so it is best to clean up the macro definition.

  Tested by building an i686-pc-cygwin toolchain.

 Cheers
  Nick

 gcc/ChangeLog
 2011-03-22  Nick Clifton  ni...@redhat.com

        * config/i386/cygming.h (SUBTARGET_OVERRIDE_OPTIONS): Remove
        trailing backslash from the end of the macro definition.

 Index: gcc/config/i386/cygming.h
 ===
 --- gcc/config/i386/cygming.h   (revision 171279)
 +++ gcc/config/i386/cygming.h   (working copy)
 @@ -207,7 +207,7 @@
               (flag_pic  1) ? PIC : pic);                         \
       flag_pic = 0;                                                    \
     }                                                                  \
 -} while (0)                                                            \
 +} while (0)

  /* Define this macro if references to a symbol must be treated
    differently depending on something about the variable or

Thanks for catching this.

Cheers,
Kai


RFC: Issue about assumption of DOSish file-system for cygwin

2011-03-22 Thread Kai Tietz
Hello,

I noticed this issue while working on those directory-separator thing
for DOSish file-systems, and somehow this looks odd to me. For some
reason the filenames.h header assumes for cygwin DOSish file-system,
but in fact cygwin uses POSIXish file-system. I assume this definition
was caused by the times cygwin compiler had -mno-cygwin option, but
well I think we should correct this by following patch.
Dave, might it be that I am overlooking here something obvious, why
cygwin should assume DOSish filesystem?

Regards,
Kai

Index: filenames.h
===
--- filenames.h (revision 171281)
+++ filenames.h (working copy)
@@ -30,7 +30,8 @@
 extern C {
 #endif

-#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) ||
defined (__CYGWIN__)
+#if (defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__)) \
+ !defined (__CYGWIN__)
 #  ifndef HAVE_DOS_BASED_FILE_SYSTEM
 #define HAVE_DOS_BASED_FILE_SYSTEM 1
 #  endif


Re: RFC: Issue about assumption of DOSish file-system for cygwin

2011-03-22 Thread Kai Tietz
2011/3/22 Pedro Alves pe...@codesourcery.com:
 On Tuesday 22 March 2011 18:11:28, Kai Tietz wrote:
 Ok, thanks for explaining it. I am just a bit concerned here about the
 ABSOLUTE path detection. As then for cygwin this will be for UNIXish
 path never true.   So it might be necessary here for cygwin case to
 allow \|/ and drive':/ for absolute path detection.

 IS_ABSOLUTE_PATH already allows that when HAVE_DOS_BASED_FILE_SYSTEM is true.

 --
 Pedro Alves


Hmm, interesting.  I look in more detail. As for DOSish file-system a
leading slash/backslash isn't necessarily an absolute path. So code is
somewhat broken for native windows.

But well, we can live by this for now.

Thanks for your time.

Kai


Re: [patch middle-end c c++]: Optimize cost of comp_type_attributes

2011-03-24 Thread Kai Tietz
2011/3/24 Jason Merrill ja...@redhat.com:
 On 03/21/2011 06:36 PM, Kai Tietz wrote:

 +      attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a)),
 +                              CONST_CAST_TREE (a2));

 I might use as-name for the name, and change lookup_attribute to take a
 const_tree rather than use CONST_CAST_TREE.

I changed patch to use as-name here instead.  The CONST_CAST_TREE
part - as we discussed on irc - is necessary, as lookup_attribute
returns as result a non-const tree.

 +  if (!a)
 +    {
 +      for (a = a2; a != NULL_TREE; a = TREE_CHAIN (a))
 +       {
 +         const struct attribute_spec *as;
 +         const_tree attr;
 +         as = lookup_attribute_spec (TREE_PURPOSE (a));
 +         if (!as || as-affects_type_identity == false)
 +           continue;
 +         attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a)),
 +                                  CONST_CAST_TREE (a1));
 +         if (!attr)
 +           break;
 +
 +         if (TREE_VALUE (a) != NULL_TREE
 +              TREE_CODE (TREE_VALUE (a)) == TREE_LIST
 +              TREE_VALUE (attr) != NULL
 +              TREE_CODE (TREE_VALUE (attr)) == TREE_LIST)
 +           {
 +             if (simple_cst_list_equal (TREE_VALUE (a),
 +                                        TREE_VALUE (attr)) == 1)
 +               break;
 +           }
 +         else if (simple_cst_equal (TREE_VALUE (a), TREE_VALUE (attr)) ==
 1)
 +           break;
 +       }

 Once we've walked the first list, we don't need to compare the values of
 common attributes again; for each attribute in the second list either it
 does appear in the first list and we've already established that they match,
 or it doesn't appear in the first list and we're done.

Yes

Updated patch attached. Ok for apply to trunk?

Regards,
Kai



-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| ()_() him gain world domination
Index: gcc/gcc/c-typeck.c
===
--- gcc.orig/gcc/c-typeck.c 2011-03-24 08:23:42.441173500 +0100
+++ gcc/gcc/c-typeck.c  2011-03-24 09:24:53.445892300 +0100
@@ -1079,7 +1079,7 @@ comptypes_internal (const_tree type1, co
 return 1;
 
   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
-  if (!(attrval = targetm.comp_type_attributes (t1, t2)))
+  if (!(attrval = comp_type_attributes (t1, t2)))
  return 0;
 
   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
Index: gcc/gcc/cp/decl.c
===
--- gcc.orig/gcc/cp/decl.c  2011-03-24 08:23:42.443173500 +0100
+++ gcc/gcc/cp/decl.c   2011-03-24 09:24:53.573408500 +0100
@@ -1012,8 +1012,8 @@ decls_match (tree newdecl, tree olddecl)
types_match =
  compparms (p1, p2)
   (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
- || targetm.comp_type_attributes (TREE_TYPE (newdecl),
-  TREE_TYPE (olddecl)) != 0);
+ || comp_type_attributes (TREE_TYPE (newdecl),
+  TREE_TYPE (olddecl)) != 0);
}
   else
types_match = 0;
Index: gcc/gcc/cp/search.c
===
--- gcc.orig/gcc/cp/search.c2011-03-24 08:23:42.444173500 +0100
+++ gcc/gcc/cp/search.c 2011-03-24 09:24:53.645417600 +0100
@@ -1897,7 +1897,7 @@ check_final_overrider (tree overrider, t
 }
 
   /* Check for conflicting type attributes.  */
-  if (!targetm.comp_type_attributes (over_type, base_type))
+  if (!comp_type_attributes (over_type, base_type))
 {
   error (conflicting type attributes specified for %q+#D, overrider);
   error (  overriding %q+#D, basefn);
Index: gcc/gcc/cp/typeck.c
===
--- gcc.orig/gcc/cp/typeck.c2011-03-24 08:23:42.495173500 +0100
+++ gcc/gcc/cp/typeck.c 2011-03-24 09:24:53.697424200 +0100
@@ -1338,7 +1338,7 @@ structural_comptypes (tree t1, tree t2,
   /* If we get here, we know that from a target independent POV the
  types are the same.  Make sure the target attributes are also
  the same.  */
-  return targetm.comp_type_attributes (t1, t2);
+  return comp_type_attributes (t1, t2);
 }
 
 /* Return true if T1 and T2 are related as allowed by STRICT.  STRICT
Index: gcc/gcc/gimple.c
===
--- gcc.orig/gcc/gimple.c   2011-03-24 08:23:42.496173500 +0100
+++ gcc/gcc/gimple.c2011-03-24 09:24:53.793936500 +0100
@@ -3615,7 +3615,7 @@ gimple_types_compatible_p_1 (tree t1, tr
 state, sccstack, sccstate, sccstate_obstack))
goto different_types;
 
-  if (!targetm.comp_type_attributes (t1, t2))
+  if (!comp_type_attributes (t1, t2))
goto different_types;
 
   if (TYPE_ARG_TYPES (t1

Re: [patch middle-end c c++]: Optimize cost of comp_type_attributes

2011-03-24 Thread Kai Tietz
2011/3/24 Jason Merrill ja...@redhat.com:
 How about splitting this out into a separate function that can compare
 either list or expression arguments?  That would also be useful for
 merge_attributes and attribute_list_contained.

 Jason


Ok, here is the patch

ChangeLog gcc/

2011-03-11  Kai Tietz

   * c-typeck.c (comptypes_internal): Replace target
   hook call of comp_type_attributes by version in tree.c file.
   * gimple.c (gimple_types_compatible_p_1): Likewise.
   * tree-ssa.c (useless_type_conversion_p): Likewise.
   * tree.c (build_type_attribute_qual_variant): Likewise.
   (attribute_equal): New static helper function.
   (comp_type_attributes): New function.
   (merge_attributes): Use attribute_equal for comparison.
   (attribute_list_contained): Likewise.
   * tree.h (comp_type_attributes): New prototype.

ChangeLog cp/

2011-03-11  Kai Tietz

   * decl.c (decls_match): Replace target hook
   call of comp_type_attributes by version in tree.c file.
   * search.c (check_final_overrider): Likewise.
   * typeck.c (structural_comptypes): Likewise.

Regards,
Kai
Index: gcc/gcc/c-typeck.c
===
--- gcc.orig/gcc/c-typeck.c 2011-03-24 08:23:42.441173500 +0100
+++ gcc/gcc/c-typeck.c  2011-03-24 09:24:53.445892300 +0100
@@ -1079,7 +1079,7 @@ comptypes_internal (const_tree type1, co
 return 1;
 
   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
-  if (!(attrval = targetm.comp_type_attributes (t1, t2)))
+  if (!(attrval = comp_type_attributes (t1, t2)))
  return 0;
 
   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
Index: gcc/gcc/cp/decl.c
===
--- gcc.orig/gcc/cp/decl.c  2011-03-24 08:23:42.443173500 +0100
+++ gcc/gcc/cp/decl.c   2011-03-24 09:24:53.573408500 +0100
@@ -1012,8 +1012,8 @@ decls_match (tree newdecl, tree olddecl)
types_match =
  compparms (p1, p2)
   (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
- || targetm.comp_type_attributes (TREE_TYPE (newdecl),
-  TREE_TYPE (olddecl)) != 0);
+ || comp_type_attributes (TREE_TYPE (newdecl),
+  TREE_TYPE (olddecl)) != 0);
}
   else
types_match = 0;
Index: gcc/gcc/cp/search.c
===
--- gcc.orig/gcc/cp/search.c2011-03-24 08:23:42.444173500 +0100
+++ gcc/gcc/cp/search.c 2011-03-24 09:24:53.645417600 +0100
@@ -1897,7 +1897,7 @@ check_final_overrider (tree overrider, t
 }
 
   /* Check for conflicting type attributes.  */
-  if (!targetm.comp_type_attributes (over_type, base_type))
+  if (!comp_type_attributes (over_type, base_type))
 {
   error (conflicting type attributes specified for %q+#D, overrider);
   error (  overriding %q+#D, basefn);
Index: gcc/gcc/cp/typeck.c
===
--- gcc.orig/gcc/cp/typeck.c2011-03-24 08:23:42.495173500 +0100
+++ gcc/gcc/cp/typeck.c 2011-03-24 09:24:53.697424200 +0100
@@ -1338,7 +1338,7 @@ structural_comptypes (tree t1, tree t2,
   /* If we get here, we know that from a target independent POV the
  types are the same.  Make sure the target attributes are also
  the same.  */
-  return targetm.comp_type_attributes (t1, t2);
+  return comp_type_attributes (t1, t2);
 }
 
 /* Return true if T1 and T2 are related as allowed by STRICT.  STRICT
Index: gcc/gcc/gimple.c
===
--- gcc.orig/gcc/gimple.c   2011-03-24 08:23:42.496173500 +0100
+++ gcc/gcc/gimple.c2011-03-24 09:24:53.793936500 +0100
@@ -3615,7 +3615,7 @@ gimple_types_compatible_p_1 (tree t1, tr
 state, sccstack, sccstate, sccstate_obstack))
goto different_types;
 
-  if (!targetm.comp_type_attributes (t1, t2))
+  if (!comp_type_attributes (t1, t2))
goto different_types;
 
   if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2))
Index: gcc/gcc/tree-ssa.c
===
--- gcc.orig/gcc/tree-ssa.c 2011-03-24 08:23:42.498173500 +0100
+++ gcc/gcc/tree-ssa.c  2011-03-24 09:24:53.831441200 +0100
@@ -1438,7 +1438,7 @@ useless_type_conversion_p (tree outer_ty
 
   /* Defer to the target if necessary.  */
   if (TYPE_ATTRIBUTES (inner_type) || TYPE_ATTRIBUTES (outer_type))
-   return targetm.comp_type_attributes (outer_type, inner_type) != 0;
+   return comp_type_attributes (outer_type, inner_type) != 0;
 
   return true;
 }
Index: gcc/gcc/tree.c
===
--- gcc.orig/gcc/tree.c 2011-03-24 08:23:42.499173500 +0100
+++ gcc/gcc/tree.c  2011-03-24 18:00

[patch i386 windows]: Introduce call-abi for 32-bit mingw and make callee_pop_aggregate_return attribute by default on for 32-bit mingw target

2011-03-24 Thread Kai Tietz
Hi,

this patch introduces for windows 32-bit target also the call-abi
specifiers (ms_abi/sys_v) and set its default for this target to
ms_abi.  This patch set the default of the
callee_pop_aggregate_return attribute to true for MS_ABI call-abi on
32-bit.  Additionally it avoids the check of
callee_pop_aggregate_return for any x86_64 target.
I didn't changed here by intention the default settings of
cygwin-target. But of course, if wished this change could be done as
follow-up patch.

ChangeLog gcc/

2011-03-24  Kai Tietz

* config/i386/cygming.h (DWARF_FRAME_REGISTERS): Adjust comment.
(STACK_BOUNDARY): Check for bit-ness in case of MS_ABI.
* config/i386/i386.c (ix86_conditional_register_usage): Adjust
comment and use macro TARGET_64BIT_MS_ABI instead.
(ix86_keep_aggregate_return_pointer): Optimize for 64-bit case
and change default behavior for 32-bit MS_ABI.
(ix86_reg_parm_stack_space): Check additionally for bit-ness.
(ix86_function_type_abi): Allow check for ms_abi/sysv_abi for
32-bit, too.
(ix86_cfun_abi): Likewise.
(ix86_maybe_switch_abi): Adjust comment.
(init_cumulative_args): Check for bit-ness in MS_ABI case.
(ix86_gimplify_va_arg): Check just for not TARGET_64BIT_MS_ABI
instead of checking for SYSV_ABI.
(ix86_nsaved_sseregs): Likewise.
(ix86_compute_frame_layout): Set only for 64-bit MS_ABI alignment
to 16 bytes.
(ix86_expand_call): Use TARGET_64BIT_MS_ABI macro.
* config/i386.h (TARGET_32BIT_MS_ABI): New macro.
(ACCUMULATE_OUTGOING_ARGS): Check explicit for 64-bit MS_ABI.
(OUTGOING_REG_PARM_STACK_SPACE): Likewise.
* config/mingw32.h (DEFAULT_ABI): Change default always to MS_ABI.

Tested for x86_64-w64-mingw32, i686-pc-cygwin, and i686-w64-mingw32.
Ok for apply?

Regards,
Kai


[PING^2]: For unreviewed patches

2011-03-25 Thread Kai Tietz
Ping for following patches

[patch libcpp]: Improve handling of DOS-filenames and -paths
http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00742.html

[patch gcc c++ c-family java fortan lto]: Fix DOS-filesystem issues
http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00824.html

Kai


Re: [patch middle-end c c++]: Optimize cost of comp_type_attributes

2011-03-25 Thread Kai Tietz
2011/3/25 Jason Merrill ja...@redhat.com:
 On 03/24/2011 08:44 PM, Kai Tietz wrote:

 +static bool
 +attribute_value_equal (const_tree attr1, const_tree attr2)
 +{
 +  if (attr1 == attr2)
 +    return true;

 I still think this test should be comparing TREE_VALUEs.

 Jason


Ok, it makes sense to check here for value indentity instead of
identity of list-node. Thanks. Updated patch attached.

Kai
Index: gcc/gcc/c-typeck.c
===
--- gcc.orig/gcc/c-typeck.c 2011-03-25 09:27:47.101196700 +0100
+++ gcc/gcc/c-typeck.c  2011-03-25 09:35:35.038738400 +0100
@@ -1079,7 +1079,7 @@ comptypes_internal (const_tree type1, co
 return 1;
 
   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
-  if (!(attrval = targetm.comp_type_attributes (t1, t2)))
+  if (!(attrval = comp_type_attributes (t1, t2)))
  return 0;
 
   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
Index: gcc/gcc/cp/decl.c
===
--- gcc.orig/gcc/cp/decl.c  2011-03-25 09:27:47.102196700 +0100
+++ gcc/gcc/cp/decl.c   2011-03-25 09:35:35.090745000 +0100
@@ -1012,8 +1012,8 @@ decls_match (tree newdecl, tree olddecl)
types_match =
  compparms (p1, p2)
   (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
- || targetm.comp_type_attributes (TREE_TYPE (newdecl),
-  TREE_TYPE (olddecl)) != 0);
+ || comp_type_attributes (TREE_TYPE (newdecl),
+  TREE_TYPE (olddecl)) != 0);
}
   else
types_match = 0;
Index: gcc/gcc/cp/search.c
===
--- gcc.orig/gcc/cp/search.c2011-03-25 09:27:47.103196700 +0100
+++ gcc/gcc/cp/search.c 2011-03-25 09:35:35.145752000 +0100
@@ -1897,7 +1897,7 @@ check_final_overrider (tree overrider, t
 }
 
   /* Check for conflicting type attributes.  */
-  if (!targetm.comp_type_attributes (over_type, base_type))
+  if (!comp_type_attributes (over_type, base_type))
 {
   error (conflicting type attributes specified for %q+#D, overrider);
   error (  overriding %q+#D, basefn);
Index: gcc/gcc/cp/typeck.c
===
--- gcc.orig/gcc/cp/typeck.c2011-03-25 09:27:47.110196700 +0100
+++ gcc/gcc/cp/typeck.c 2011-03-25 09:35:35.164754400 +0100
@@ -1338,7 +1338,7 @@ structural_comptypes (tree t1, tree t2,
   /* If we get here, we know that from a target independent POV the
  types are the same.  Make sure the target attributes are also
  the same.  */
-  return targetm.comp_type_attributes (t1, t2);
+  return comp_type_attributes (t1, t2);
 }
 
 /* Return true if T1 and T2 are related as allowed by STRICT.  STRICT
Index: gcc/gcc/gimple.c
===
--- gcc.orig/gcc/gimple.c   2011-03-25 09:27:47.112196700 +0100
+++ gcc/gcc/gimple.c2011-03-25 09:35:35.206259700 +0100
@@ -3615,7 +3615,7 @@ gimple_types_compatible_p_1 (tree t1, tr
 state, sccstack, sccstate, sccstate_obstack))
goto different_types;
 
-  if (!targetm.comp_type_attributes (t1, t2))
+  if (!comp_type_attributes (t1, t2))
goto different_types;
 
   if (TYPE_ARG_TYPES (t1) == TYPE_ARG_TYPES (t2))
Index: gcc/gcc/tree-ssa.c
===
--- gcc.orig/gcc/tree-ssa.c 2011-03-25 09:27:47.113196700 +0100
+++ gcc/gcc/tree-ssa.c  2011-03-25 09:35:35.231762900 +0100
@@ -1438,7 +1438,7 @@ useless_type_conversion_p (tree outer_ty
 
   /* Defer to the target if necessary.  */
   if (TYPE_ATTRIBUTES (inner_type) || TYPE_ATTRIBUTES (outer_type))
-   return targetm.comp_type_attributes (outer_type, inner_type) != 0;
+   return comp_type_attributes (outer_type, inner_type) != 0;
 
   return true;
 }
Index: gcc/gcc/tree.c
===
--- gcc.orig/gcc/tree.c 2011-03-25 09:31:02.378615000 +0100
+++ gcc/gcc/tree.c  2011-03-25 10:48:15.141401100 +0100
@@ -4287,7 +4287,7 @@ build_type_attribute_qual_variant (tree
 its canonical type, we will need to use structural equality
 checks for this type. */
   if (TYPE_STRUCTURAL_EQUALITY_P (ttype)
-  || !targetm.comp_type_attributes (ntype, ttype))
+  || !comp_type_attributes (ntype, ttype))
SET_TYPE_STRUCTURAL_EQUALITY (ntype);
   else if (TYPE_CANONICAL (ntype) == ntype)
TYPE_CANONICAL (ntype) = TYPE_CANONICAL (ttype);
@@ -4300,6 +4300,75 @@ build_type_attribute_qual_variant (tree
   return ttype;
 }
 
+/* Compare two attributes for their value identity.  Return true if the
+   attribute values are known to be equal; otherwise return false.
+*/
+
+static bool

Re: [patch middle-end c c++]: Optimize cost of comp_type_attributes

2011-03-25 Thread Kai Tietz
2011/3/25 Jason Merrill ja...@redhat.com:
 OK.

 Jason


Committed at revision 171445.

Thanks,
Kai


Re: [PING^2]: For unreviewed patches

2011-03-25 Thread Kai Tietz
2011/3/25 Jeff Law l...@redhat.com:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 On 03/25/11 02:48, Kai Tietz wrote:
 Ping for following patches

 [patch libcpp]: Improve handling of DOS-filenames and -paths
 http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00742.html

 [patch gcc c++ c-family java fortan lto]: Fix DOS-filesystem issues
 http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00824.html
 OK for both.

 Thanks,
 Jeff

Committed at revision 171521 and revision 171522.

Thanks,
Kai


[patch ada]: Fix issues about multilib build of native windows and handle MSG_WAITALL for windows native targets

2011-03-28 Thread Kai Tietz
Hello,

this patch fixes some nits about MSG_WAITALL for mingw(-w64) targets.
Additionally it improves multilib configury for windows native
targets.

ChangeLog gcc/ada

2011-03-28  Kai Tietz

* raise-gcc.c (PERSONALITY_FUNCTION): Add prototype to
prevent warning.
* g-socthi-mingw.adb (C_Recvmsg): Handle MSG_WAITALL for
windows native targets.
* s-oscons-tmplt.c (MSG_WAITALL): Define it for native windows
targets to flag value.
* gcc-interface/Makefile.in (SO_LIB): Handle multilib build for native
windows targets.
(EH_MECHANISM): Make sure we use gcc's exception mechanism for 64-bit
native windows target.

Tested for x86_64-w64-mingw32 and i686-w64-mingw32 targets. Ok for apply?

Regards,
Kai
Index: gcc/gcc/ada/g-socthi-mingw.adb
===
--- gcc.orig/gcc/ada/g-socthi-mingw.adb 2010-09-09 16:07:42.0 +0200
+++ gcc/gcc/ada/g-socthi-mingw.adb  2011-03-28 09:42:45.039326300 +0200
@@ -277,7 +277,8 @@ package body GNAT.Sockets.Thin is
   use type C.size_t;
 
   Fill  : constant Boolean :=
-(C.unsigned (Flags) and SOSC.MSG_WAITALL) /= 0;
+SOSC.MSG_WAITALL /= -1
+and then (C.unsigned (Flags) and SOSC.MSG_WAITALL) /= 0;
   --  Is the MSG_WAITALL flag set? If so we need to fully fill all vectors
 
   Res   : C.int;
Index: gcc/gcc/ada/gcc-interface/Makefile.in
===
--- gcc.orig/gcc/ada/gcc-interface/Makefile.in  2011-03-28 09:27:19.0 
+0200
+++ gcc/gcc/ada/gcc-interface/Makefile.in   2011-03-28 09:26:53.759029000 
+0200
@@ -1638,17 +1638,23 @@ ifeq ($(strip $(filter-out cygwin32% min
   ifeq ($(strip $(MULTISUBDIR)),/32)
LIBGNAT_TARGET_PAIRS += \
  system.adssystem-mingw.ads
+   SO_OPTS= -m32 -Wl,-soname,
   else
LIBGNAT_TARGET_PAIRS += \
  system.adssystem-mingw-x86_64.ads
+   EH_MECHANISM=-gcc
+   SO_OPTS = -m64 -Wl,-soname,
   endif
 else
   ifeq ($(strip $(MULTISUBDIR)),/64)
LIBGNAT_TARGET_PAIRS += \
  system.adssystem-mingw-x86_64.ads
+   EH_MECHANISM=-gcc
+   SO_OPTS = -m64 -Wl,-soname,
   else
LIBGNAT_TARGET_PAIRS += \
  system.adssystem-mingw.ads
+   SO_OPTS = -m32 -Wl,-soname,
   endif
 endif
 
Index: gcc/gcc/ada/raise-gcc.c
===
--- gcc.orig/gcc/ada/raise-gcc.c2010-10-28 22:36:06.0 +0200
+++ gcc/gcc/ada/raise-gcc.c 2011-03-28 09:11:43.053384100 +0200
@@ -1065,6 +1065,11 @@ typedef _Unwind_Action phases_arg_t;
 #endif
 
 _Unwind_Reason_Code
+PERSONALITY_FUNCTION (version_arg_t, phases_arg_t,
+  _Unwind_Exception_Class, _Unwind_Exception *,
+  _Unwind_Context *);
+
+_Unwind_Reason_Code
 PERSONALITY_FUNCTION (version_arg_t version_arg,
   phases_arg_t phases_arg,
   _Unwind_Exception_Class uw_exception_class,
Index: gcc/gcc/ada/s-oscons-tmplt.c
===
--- gcc.orig/gcc/ada/s-oscons-tmplt.c   2010-12-24 11:41:57.0 +0100
+++ gcc/gcc/ada/s-oscons-tmplt.c2011-03-28 09:15:39.683932300 +0200
@@ -1084,6 +1084,10 @@ CND(MSG_PEEK, Peek at incoming data)
 CND(MSG_EOR, Send end of record)
 
 #ifndef MSG_WAITALL
+#ifdef __MINWGW32__
+/* We use it on windows native targets, so set to flag value.  */
+# define MSG_WAITALL (1  2)
+#else
 # define MSG_WAITALL -1
 #endif
 CND(MSG_WAITALL, Wait for full reception)


Re: [patch ada]: Fix issues about multilib build of native windows and handle MSG_WAITALL for windows native targets

2011-03-28 Thread Kai Tietz
2011/3/28 Arnaud Charlet char...@adacore.com:
 this patch fixes some nits about MSG_WAITALL for mingw(-w64) targets.
 Additionally it improves multilib configury for windows native
 targets.

 Can you please split this patch in two, since the MSG_WAITALL is one thing,
 and the multilib is a completely different patch.

Hello Arno,

I split patch into two. ada_w_multi.txt contains just the
gcc-interface/Makefile.in change and the ada_wt.txt the MSG_WAITALL
patch.

ChangeLog gcc/ada (ada_wt.txt)

2011-03-28  Kai Tietz

* raise-gcc.c (PERSONALITY_FUNCTION): Add prototype to
prevent warning.
* g-socthi-mingw.adb (C_Recvmsg): Handle MSG_WAITALL for
windows native targets.
* s-oscons-tmplt.c (MSG_WAITALL): Define it for native windows
targets to flag value.

ChangeLog gcc/ada (ada_w_multi.txt)

2011-03-28  Kai Tietz

* gcc-interface/Makefile.in (SO_LIB): Handle multilib build for native
windows targets.
(EH_MECHANISM): Make sure we use gcc's exception mechanism for 64-bit
native windows target.


 Also, can you explain the setting of SO_LIB in more details?

The issue is that on creation of .dll the linker has to know for
multilib for which target it should work. By specifying to frontend
the -m32/-m64 the internal spec-file takes care that proper options
are passed to ld.

 Concerning the setting of EH_MECHANISM, it's time to set ZCX to True by
 default on Windows 32bits as well, and set EH_MECHANISM=-gcc on all
 Windows variants IMO.

Well, here I am not that sure.  As mingw.org is still using the
dw2-unwinding, but there is also the sjlj one, I am a bit concerned to
make EH_MECHANISM=-gcc default. Same is the case for the ZCX flag, but
I might overlook here something obvious.

Regards,
Kai
Index: gcc/gcc/ada/gcc-interface/Makefile.in
===
--- gcc.orig/gcc/ada/gcc-interface/Makefile.in  2011-03-28 10:29:44.0 
+0200
+++ gcc/gcc/ada/gcc-interface/Makefile.in   2011-03-28 10:32:28.890727300 
+0200
@@ -1638,17 +1638,23 @@ ifeq ($(strip $(filter-out cygwin32% min
   ifeq ($(strip $(MULTISUBDIR)),/32)
LIBGNAT_TARGET_PAIRS += \
  system.adssystem-mingw.ads
+   SO_OPTS= -m32 -Wl,-soname,
   else
LIBGNAT_TARGET_PAIRS += \
  system.adssystem-mingw-x86_64.ads
+   EH_MECHANISM=-gcc
+   SO_OPTS = -m64 -Wl,-soname,
   endif
 else
   ifeq ($(strip $(MULTISUBDIR)),/64)
LIBGNAT_TARGET_PAIRS += \
  system.adssystem-mingw-x86_64.ads
+   EH_MECHANISM=-gcc
+   SO_OPTS = -m64 -Wl,-soname,
   else
LIBGNAT_TARGET_PAIRS += \
  system.adssystem-mingw.ads
+   SO_OPTS = -m32 -Wl,-soname,
   endif
 endif
 
Index: gcc/gcc/ada/g-socthi-mingw.adb
===
--- gcc.orig/gcc/ada/g-socthi-mingw.adb 2010-09-09 16:07:42.0 +0200
+++ gcc/gcc/ada/g-socthi-mingw.adb  2011-03-28 09:42:45.039326300 +0200
@@ -277,7 +277,8 @@ package body GNAT.Sockets.Thin is
   use type C.size_t;
 
   Fill  : constant Boolean :=
-(C.unsigned (Flags) and SOSC.MSG_WAITALL) /= 0;
+SOSC.MSG_WAITALL /= -1
+and then (C.unsigned (Flags) and SOSC.MSG_WAITALL) /= 0;
   --  Is the MSG_WAITALL flag set? If so we need to fully fill all vectors
 
   Res   : C.int;
Index: gcc/gcc/ada/raise-gcc.c
===
--- gcc.orig/gcc/ada/raise-gcc.c2010-10-28 22:36:06.0 +0200
+++ gcc/gcc/ada/raise-gcc.c 2011-03-28 09:11:43.053384100 +0200
@@ -1065,6 +1065,11 @@ typedef _Unwind_Action phases_arg_t;
 #endif
 
 _Unwind_Reason_Code
+PERSONALITY_FUNCTION (version_arg_t, phases_arg_t,
+  _Unwind_Exception_Class, _Unwind_Exception *,
+  _Unwind_Context *);
+
+_Unwind_Reason_Code
 PERSONALITY_FUNCTION (version_arg_t version_arg,
   phases_arg_t phases_arg,
   _Unwind_Exception_Class uw_exception_class,
Index: gcc/gcc/ada/s-oscons-tmplt.c
===
--- gcc.orig/gcc/ada/s-oscons-tmplt.c   2010-12-24 11:41:57.0 +0100
+++ gcc/gcc/ada/s-oscons-tmplt.c2011-03-28 09:15:39.683932300 +0200
@@ -1084,6 +1084,10 @@ CND(MSG_PEEK, Peek at incoming data)
 CND(MSG_EOR, Send end of record)
 
 #ifndef MSG_WAITALL
+#ifdef __MINWGW32__
+/* We use it on windows native targets, so set to flag value.  */
+# define MSG_WAITALL (1  2)
+#else
 # define MSG_WAITALL -1
 #endif
 CND(MSG_WAITALL, Wait for full reception)


Re: [patch ada]: Fix issues about multilib build of native windows and handle MSG_WAITALL for windows native targets

2011-03-28 Thread Kai Tietz
2011/3/28 Kai Tietz ktiet...@googlemail.com:

 ChangeLog gcc/ada (ada_wt.txt)

 2011-03-28  Kai Tietz

        * raise-gcc.c (PERSONALITY_FUNCTION): Add prototype to
        prevent warning.
        * g-socthi-mingw.adb (C_Recvmsg): Handle MSG_WAITALL for
        windows native targets.
        * s-oscons-tmplt.c (MSG_WAITALL): Define it for native windows
        targets to flag value.

Just noticed I had a wrong shift-value for MSG_WAITALL. It should be
8. Updated patch attached.

Kai
Index: gcc/gcc/ada/g-socthi-mingw.adb
===
--- gcc.orig/gcc/ada/g-socthi-mingw.adb 2010-09-09 16:07:42.0 +0200
+++ gcc/gcc/ada/g-socthi-mingw.adb  2011-03-28 09:42:45.039326300 +0200
@@ -277,7 +277,8 @@ package body GNAT.Sockets.Thin is
   use type C.size_t;
 
   Fill  : constant Boolean :=
-(C.unsigned (Flags) and SOSC.MSG_WAITALL) /= 0;
+SOSC.MSG_WAITALL /= -1
+and then (C.unsigned (Flags) and SOSC.MSG_WAITALL) /= 0;
   --  Is the MSG_WAITALL flag set? If so we need to fully fill all vectors
 
   Res   : C.int;
Index: gcc/gcc/ada/raise-gcc.c
===
--- gcc.orig/gcc/ada/raise-gcc.c2010-10-28 22:36:06.0 +0200
+++ gcc/gcc/ada/raise-gcc.c 2011-03-28 09:11:43.053384100 +0200
@@ -1065,6 +1065,11 @@ typedef _Unwind_Action phases_arg_t;
 #endif
 
 _Unwind_Reason_Code
+PERSONALITY_FUNCTION (version_arg_t, phases_arg_t,
+  _Unwind_Exception_Class, _Unwind_Exception *,
+  _Unwind_Context *);
+
+_Unwind_Reason_Code
 PERSONALITY_FUNCTION (version_arg_t version_arg,
   phases_arg_t phases_arg,
   _Unwind_Exception_Class uw_exception_class,
Index: gcc/gcc/ada/s-oscons-tmplt.c
===
--- gcc.orig/gcc/ada/s-oscons-tmplt.c   2010-12-24 11:41:57.0 +0100
+++ gcc/gcc/ada/s-oscons-tmplt.c2011-03-28 09:15:39.683932300 +0200
@@ -1084,6 +1084,10 @@ CND(MSG_PEEK, Peek at incoming data)
 CND(MSG_EOR, Send end of record)
 
 #ifndef MSG_WAITALL
+#ifdef __MINWGW32__
+/* We use it on windows native targets, so set to flag value.  */
+# define MSG_WAITALL (1  3)
+#else
 # define MSG_WAITALL -1
 #endif
 CND(MSG_WAITALL, Wait for full reception)


[patch ada]: Prevent warning about PERSONALITY_FUNCTION in raise-gcc.c

2011-03-28 Thread Kai Tietz
Hello,

Split submitted patch from thread [patch ada]: Fix issues about
multilib build of native windows and handle MSG_WAITALL for windows
native targets
into separate ones.

ChangeLog gcc/ada

2011-03-28  Kai Tietz

* raise-gcc.c (PERSONALITY_FUNCTION): Add prototype to
prevent warning.

Regards,
Kai
Index: gcc/gcc/ada/raise-gcc.c
===
--- gcc.orig/gcc/ada/raise-gcc.c2011-03-28 10:56:51.0 +0200
+++ gcc/gcc/ada/raise-gcc.c 2011-03-28 11:21:37.453647200 +0200
@@ -1065,6 +1065,11 @@ typedef _Unwind_Action phases_arg_t;
 #endif
 
 _Unwind_Reason_Code
+PERSONALITY_FUNCTION (version_arg_t, phases_arg_t,
+  _Unwind_Exception_Class, _Unwind_Exception *,
+  _Unwind_Context *);
+
+_Unwind_Reason_Code
 PERSONALITY_FUNCTION (version_arg_t version_arg,
   phases_arg_t phases_arg,
   _Unwind_Exception_Class uw_exception_class,


[patch ada]: Fix MSG_WAITALL handling for windows native targets

2011-03-28 Thread Kai Tietz
Hello,

Split submitted patch from thread [patch ada]: Fix issues about
multilib build of native windows and handle MSG_WAITALL for windows
native targets
into separate ones.

ChangeLog gcc/ada (ada_wt.txt)

2011-03-28  Kai Tietz

* g-socthi-mingw.adb (C_Recvmsg): Handle MSG_WAITALL for
windows native targets.
* s-oscons-tmplt.c (MSG_WAITALL): Define it for native windows
targets to flag value.

Regards,
Kai
Index: gcc/gcc/ada/g-socthi-mingw.adb
===
--- gcc.orig/gcc/ada/g-socthi-mingw.adb 2010-09-09 16:07:42.0 +0200
+++ gcc/gcc/ada/g-socthi-mingw.adb  2011-03-28 09:42:45.039326300 +0200
@@ -277,7 +277,8 @@ package body GNAT.Sockets.Thin is
   use type C.size_t;
 
   Fill  : constant Boolean :=
-(C.unsigned (Flags) and SOSC.MSG_WAITALL) /= 0;
+SOSC.MSG_WAITALL /= -1
+and then (C.unsigned (Flags) and SOSC.MSG_WAITALL) /= 0;
   --  Is the MSG_WAITALL flag set? If so we need to fully fill all vectors
 
   Res   : C.int;
Index: gcc/gcc/ada/s-oscons-tmplt.c
===
--- gcc.orig/gcc/ada/s-oscons-tmplt.c   2010-12-24 11:41:57.0 +0100
+++ gcc/gcc/ada/s-oscons-tmplt.c2011-03-28 09:15:39.683932300 +0200
@@ -1084,6 +1084,10 @@ CND(MSG_PEEK, Peek at incoming data)
 CND(MSG_EOR, Send end of record)
 
 #ifndef MSG_WAITALL
+#ifdef __MINWGW32__
+/* We use it on windows native targets, so set to flag value.  */
+# define MSG_WAITALL (1  3)
+#else
 # define MSG_WAITALL -1
 #endif
 CND(MSG_WAITALL, Wait for full reception)


[patch ada]: Fix issues about multilib build of native windows

2011-03-28 Thread Kai Tietz
Hello,

Split submitted patch from thread [patch ada]: Fix issues about
multilib build of native windows and handle MSG_WAITALL for windows
native targets
into separate ones.

ChangeLog gcc/ada (ada_w_multi.txt)

2011-03-28  Kai Tietz

* gcc-interface/Makefile.in (SO_LIB): Handle multilib build for native
windows targets.
(EH_MECHANISM): Make sure we use gcc's exception mechanism for all
native windows target.
* system-mingw.ads (System): Change ZCX_By_Default default to
True.

Regards,
Kai
Index: gcc/gcc/ada/gcc-interface/Makefile.in
===
--- gcc.orig/gcc/ada/gcc-interface/Makefile.in  2011-03-28 10:56:42.202851800 
+0200
+++ gcc/gcc/ada/gcc-interface/Makefile.in   2011-03-28 11:35:38.320423700 
+0200
@@ -1634,21 +1634,26 @@ ifeq ($(strip $(filter-out cygwin32% min
 s-osprim.adbs-osprim-mingw.adb \
 s-taprop.adbs-taprop-mingw.adb
 
+EH_MECHANISM=-gcc
 ifeq ($(strip $(filter-out x86_64%,$(arch))),)
   ifeq ($(strip $(MULTISUBDIR)),/32)
LIBGNAT_TARGET_PAIRS += \
  system.adssystem-mingw.ads
+   SO_OPTS= -m32 -Wl,-soname,
   else
LIBGNAT_TARGET_PAIRS += \
  system.adssystem-mingw-x86_64.ads
+   SO_OPTS = -m64 -Wl,-soname,
   endif
 else
   ifeq ($(strip $(MULTISUBDIR)),/64)
LIBGNAT_TARGET_PAIRS += \
  system.adssystem-mingw-x86_64.ads
+   SO_OPTS = -m64 -Wl,-soname,
   else
LIBGNAT_TARGET_PAIRS += \
  system.adssystem-mingw.ads
+   SO_OPTS = -m32 -Wl,-soname,
   endif
 endif
 
Index: gcc/gcc/ada/system-mingw.ads
===
--- gcc.orig/gcc/ada/system-mingw.ads   2010-09-09 16:07:48.0 +0200
+++ gcc/gcc/ada/system-mingw.ads2011-03-28 11:31:31.668102900 +0200
@@ -139,7 +139,7 @@ private
Always_Compatible_Rep : constant Boolean := False;
Suppress_Standard_Library : constant Boolean := False;
Use_Ada_Main_Program_Name : constant Boolean := False;
-   ZCX_By_Default: constant Boolean := False;
+   ZCX_By_Default: constant Boolean := True;
GCC_ZCX_Support   : constant Boolean := True;
 
---


Re: [patch ada]: Fix issues about multilib build of native windows and handle MSG_WAITALL for windows native targets

2011-03-28 Thread Kai Tietz
2011/3/28 Arnaud Charlet char...@adacore.com:
 I split patch into two. ada_w_multi.txt contains just the
 gcc-interface/Makefile.in change and the ada_wt.txt the MSG_WAITALL
 patch.

 Thanks. Actually raise-gcc.c is yet another issue.

 Could you please resubmit under three different emails/threads your
 3 different patches, so that they can be reviewed and OKed independently
 (and potentially by different people)? TIA.

 The issue is that on creation of .dll the linker has to know for
 multilib for which target it should work. By specifying to frontend
 the -m32/-m64 the internal spec-file takes care that proper options
 are passed to ld.

 Thanks for the clarification.

  Concerning the setting of EH_MECHANISM, it's time to set ZCX to True by
  default on Windows 32bits as well, and set EH_MECHANISM=-gcc on all
  Windows variants IMO.

 Well, here I am not that sure.  As mingw.org is still using the
 dw2-unwinding, but there is also the sjlj one, I am a bit concerned to
 make EH_MECHANISM=-gcc default. Same is the case for the ZCX flag, but
 I might overlook here something obvious.

 We've been using ZCX by default at AdaCore for several years now, so it's
 time to switch the default at the FSF as well I think, in particular since
 you are suggesting a patch that will make Makefile.in more complex (and
 hence harder to maintain) for no reason without this change.

 Arno


Ok, done.

Kai


Re: [patch ada]: Prevent warning about PERSONALITY_FUNCTION in raise-gcc.c

2011-03-28 Thread Kai Tietz
2011/3/28 Arnaud Charlet char...@adacore.com:
 Split submitted patch from thread [patch ada]: Fix issues about
 multilib build of native windows and handle MSG_WAITALL for windows
 native targets
 into separate ones.

 ChangeLog gcc/ada

 2011-03-28  Kai Tietz

       * raise-gcc.c (PERSONALITY_FUNCTION): Add prototype to
       prevent warning.

 OK, thanks for resubmitting separately.

Committed at revision 171594.

Thanks,
Kai


Re: [patch ada]: Fix MSG_WAITALL handling for windows native targets

2011-03-28 Thread Kai Tietz
2011/3/28 Arnaud Charlet char...@adacore.com:
 Kai,

 Here are Thomas comments on your patch:

 --
 Split submitted patch from thread [patch ada]: Fix issues about
 multilib build of native windows and handle MSG_WAITALL for windows
 native targets
 into separate ones.

 ChangeLog gcc/ada (ada_wt.txt)

 2011-03-28  Kai Tietz

       * g-socthi-mingw.adb (C_Recvmsg): Handle MSG_WAITALL for
       windows native targets.
       * s-oscons-tmplt.c (MSG_WAITALL): Define it for native windows
       targets to flag value.

        Fill  : constant Boolean :=
 -                (C.unsigned (Flags) and SOSC.MSG_WAITALL) /= 0;
 +                SOSC.MSG_WAITALL /= -1
 +                and then (C.unsigned (Flags) and SOSC.MSG_WAITALL) /= 0;
        --  Is the MSG_WAITALL flag set? If so we need to fully fill all 
 vectors

 Not sure about this. The other change (to s-oscons-tmplt.c) causes
 SOSC.MSG_WAITALL to always be defined to 8 in the Windows case, so the
 new test against -1 (which would have been relevant without the other
 change) now becomes redundant.

Well, I can remove it from patch. But IMHO it would be good to fix
here logic, even if it has obviously no effect here anymore.  As often
such code simply gets copy  pasted and then a latent bug can be
copied.

  #ifndef MSG_WAITALL
 +#ifdef __MINWGW32__
 +/* We use it on windows native targets, so set to flag value.  */
 +# define MSG_WAITALL (1  3)
 +#else

 The comment is completely meaningless and should be rewritten. In
 particular a note should be added to explain why this will work even
 though MSG_WAITALL is not defined in the Winsock header files.

Yes, I wrote some more details about this definition.  It is related
to the use of winsock/winsock2. The define MSG_WAITALL is just defined
for wsock API 2. Nevertheless we link internally against wsock2-API
(ws2_32), and so it is available anyway.

Updated patch attached.

Regards,
Kai
Index: gcc/gcc/ada/g-socthi-mingw.adb
===
--- gcc.orig/gcc/ada/g-socthi-mingw.adb 2011-03-28 11:40:51.941851800 +0200
+++ gcc/gcc/ada/g-socthi-mingw.adb  2011-03-28 13:09:04.309293900 +0200
@@ -277,7 +277,8 @@ package body GNAT.Sockets.Thin is
   use type C.size_t;
 
   Fill  : constant Boolean :=
-(C.unsigned (Flags) and SOSC.MSG_WAITALL) /= 0;
+SOSC.MSG_WAITALL /= -1
+and then (C.unsigned (Flags) and SOSC.MSG_WAITALL) /= 0;
   --  Is the MSG_WAITALL flag set? If so we need to fully fill all vectors
 
   Res   : C.int;
Index: gcc/gcc/ada/s-oscons-tmplt.c
===
--- gcc.orig/gcc/ada/s-oscons-tmplt.c   2011-03-28 11:40:51.949851800 +0200
+++ gcc/gcc/ada/s-oscons-tmplt.c2011-03-28 13:13:51.479759900 +0200
@@ -1084,6 +1084,11 @@ CND(MSG_PEEK, Peek at incoming data)
 CND(MSG_EOR, Send end of record)
 
 #ifndef MSG_WAITALL
+#ifdef __MINWGW32__
+/* The value of MSG_WAITALL is 8.  Nevertheless winsock.h doesn't
+   define it, but it is still usable as we link to winsock2 API.  */
+# define MSG_WAITALL (1  3)
+#else
 # define MSG_WAITALL -1
 #endif
 CND(MSG_WAITALL, Wait for full reception)


Re: [patch mingw]: Enable optional thread-model posix for mingw-targets

2011-04-01 Thread Kai Tietz
2011/3/31 Ralf Wildenhues ralf.wildenh...@gmx.de:
 * Kai Tietz wrote on Thu, Mar 31, 2011 at 12:19:51PM CEST:
 --- gcc.orig/gcc/config.gcc   2011-03-23 21:15:32.0 +0100
 +++ gcc/gcc/config.gcc        2011-03-31 10:50:05.559129000 +0200

 @@ -1420,6 +1420,10 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
               *)
                       ;;
       esac
 +     if test x$enable_threads = xposix ; then
 +             tm_file=${tm_file} i386/mingw-pthread.h
 +     fi
 +     tm_file=${tm_file} i386/mingw32.h
       # This makes the logic if mingw's or the w64 feature set has to be used
       case ${target} in
               *-w64-*)
 @@ -1486,10 +1490,14 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
       cxx_target_objs=${cxx_target_objs} winnt-cxx.o msformat-c.o
       default_use_cxa_atexit=yes
       use_gcc_stdint=wrap
 -     case ${enable_threads} in
 -        | yes | win32)       thread_file='win32'
 -       tmake_file=${tmake_file} i386/t-gthr-win32
 -       ;;
 +     case x${enable_threads} in
 +       x | xyes | xwin32)      thread_file='win32'
 +         tmake_file=${tmake_file} i386/t-gthr-win32
 +         ;;
 +       xposix)
 +         thread_file='posix'
 +         tmake_file=i386/t-mingw-pthread ${tmake_file}
 +         ;;
       esac

 For what it's worth, the 'x' escaping is not ever needed for case
 statements (unlike for some 'test' statements), so you can write

  case $enable_threads in
   | yes | win32) ...
  posix) ...
  esac

 Cheers,
 Ralf


Applied patch at revision 171833 with the adjustment Ralf suggested.

Regards,
Kai


Re: [patch i386]: Set for method-functions default calling-convention to thiscall for 32-bit msabi

2011-04-01 Thread Kai Tietz
2011/4/1 Nathan Froyd froy...@codesourcery.com:
 On Fri, Apr 01, 2011 at 07:39:13PM +0200, Kai Tietz wrote:
 this patch sets for c++ methods, which are not stdarg ones, the
 default calling-convention to thiscall for ms_abi 32-bit, as vendor
 specific compiler does.

 I think it might be worthwhile to pull this pattern:

 @@ -5500,7 +5524,8 @@ ix86_function_regparm (const_tree type,
    if (lookup_attribute (fastcall, TYPE_ATTRIBUTES (type)))
      return 2;

 -  if (lookup_attribute (thiscall, TYPE_ATTRIBUTES (type)))
 +  if (lookup_attribute (thiscall, TYPE_ATTRIBUTES (type))
 +      || ix86_is_msabi_thiscall (type))

 into a separate function.?  That function could also be used for
 negative tests like this one:

 @@ -9799,7 +9826,8 @@ find_drap_reg (void)
          !lookup_attribute (fastcall,
                               TYPE_ATTRIBUTES (TREE_TYPE (decl)))
          !lookup_attribute (thiscall,
 -                             TYPE_ATTRIBUTES (TREE_TYPE (decl
 +                             TYPE_ATTRIBUTES (TREE_TYPE (decl)))
 +        ! ix86_is_msabi_thiscall (TREE_TYPE (decl)))

 WDYT?

 -Nathan


Nathan, good idea. I modified patch for this.

ChangeLog

2011-04-01  Kai Tietz

* i386.c (ix86_is_msabi_thiscall): New helper function.
(ix86_is_type_thiscall): New helper function.
(ix86_comp_type_attributes): Handle thiscall for method-functions
special.
(init_cumulative_args): Likewise.
(find_drap_reg): Likewise.
(ix86_static_chain): Likewise.
(x86_this_parameter): Likewise.
(x86_output_mi_thunk): Likewise.

Regards,
Kai
Index: gcc/gcc/config/i386/i386.c
===
--- gcc.orig/gcc/config/i386/i386.c 2011-04-01 18:26:53.207236300 +0200
+++ gcc/gcc/config/i386/i386.c  2011-04-01 20:08:15.344145300 +0200
@@ -5436,6 +5436,33 @@ ix86_handle_cconv_attribute (tree *node,
   return NULL_TREE;
 }
 
+/* This function checks if the method-function has default __thiscall
+   calling-convention for 32-bit msabi.
+   It returns true if TYPE is of kind METHOD_TYPE, no stdarg function,
+   and the MS_ABI 32-bit is used.  Otherwise it returns false.  */
+
+static bool
+ix86_is_msabi_thiscall (const_tree type)
+{
+  if (TARGET_64BIT || ix86_function_type_abi (type) != MS_ABI
+  || TREE_CODE (type) != METHOD_TYPE || stdarg_p (type))
+return false;
+  return true;
+}
+
+/* This function checks if the thiscall attribute is set for the TYPE,
+   or if it is an method-type with default thiscall convention.
+   It returns true if function match, otherwise false is returned.  */
+
+static bool
+ix86_is_type_thiscall (const_tree type)
+{
+  if (lookup_attribute (thiscall, TYPE_ATTRIBUTES (type))
+  || ix86_is_msabi_thiscall (type))
+return true;
+  return false;
+}
+
 /* Return 0 if the attributes for two types are incompatible, 1 if they
are compatible, and 2 if they are nearly compatible (which causes a
warning to be generated).  */
@@ -5444,7 +5471,8 @@ static int
 ix86_comp_type_attributes (const_tree type1, const_tree type2)
 {
   /* Check for mismatch of non-default calling convention.  */
-  const char *const rtdstr = TARGET_RTD ? cdecl : stdcall;
+  bool is_thiscall = ix86_is_msabi_thiscall (type1);
+  const char *const rtdstr = TARGET_RTD ? (is_thiscall ? thiscall : cdecl) 
: stdcall;
 
   if (TREE_CODE (type1) != FUNCTION_TYPE
TREE_CODE (type1) != METHOD_TYPE)
@@ -5463,9 +5491,18 @@ ix86_comp_type_attributes (const_tree ty
 return 0;
 
   /* Check for mismatched thiscall types.  */
-  if (!lookup_attribute (thiscall, TYPE_ATTRIBUTES (type1))
-  != !lookup_attribute (thiscall, TYPE_ATTRIBUTES (type2)))
-return 0;
+  if (is_thiscall  !TARGET_RTD)
+{
+  if (!lookup_attribute (cdecl, TYPE_ATTRIBUTES (type1))
+ != !lookup_attribute (cdecl, TYPE_ATTRIBUTES (type2)))
+   return 0;
+}
+  else if (!is_thiscall || TARGET_RTD)
+{
+  if (!lookup_attribute (thiscall, TYPE_ATTRIBUTES (type1))
+ != !lookup_attribute (thiscall, TYPE_ATTRIBUTES (type2)))
+   return 0;
+}
 
   /* Check for mismatched return types (cdecl vs stdcall).  */
   if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
@@ -5500,7 +5537,7 @@ ix86_function_regparm (const_tree type,
   if (lookup_attribute (fastcall, TYPE_ATTRIBUTES (type)))
 return 2;
 
-  if (lookup_attribute (thiscall, TYPE_ATTRIBUTES (type)))
+  if (ix86_is_type_thiscall (type))
 return 1;
 
   /* Use register calling convention for local functions when possible.  */
@@ -5666,7 +5703,7 @@ ix86_return_pops_args (tree fundecl, tre
  variable args.  */
   if (lookup_attribute (stdcall, TYPE_ATTRIBUTES (funtype))
  || lookup_attribute (fastcall, TYPE_ATTRIBUTES (funtype))
-  || lookup_attribute (thiscall, TYPE_ATTRIBUTES (funtype)))
+  || ix86_is_type_thiscall (funtype))
rtd = 1;
 
   if (rtd  ! stdarg_p (funtype

Re: [patch i386]: Set for method-functions default calling-convention to thiscall for 32-bit msabi

2011-04-01 Thread Kai Tietz
2011/4/1 Richard Henderson r...@redhat.com:
 On 04/01/2011 11:10 AM, Kai Tietz wrote:
       * i386.c (ix86_is_msabi_thiscall): New helper function.
       (ix86_is_type_thiscall): New helper function.
       (ix86_comp_type_attributes): Handle thiscall for method-functions
       special.
       (init_cumulative_args): Likewise.
       (find_drap_reg): Likewise.
       (ix86_static_chain): Likewise.
       (x86_this_parameter): Likewise.
       (x86_output_mi_thunk): Likewise.

 Ok.


 r~


I just found a nit about thiscall default and checking of other
calling-conventions. I've updated patch in ix86_is_msabi_thiscall so
that it checks explicit for different calling-abis.
It might be a good thing to extract those call-abi lookups into a
specific function, which returns numbers for the selected on. By this
we can avoid double lookup of attributes here.
But I would like to do this in a separate patch.

Regards,
Kai
Index: gcc/gcc/config/i386/i386.c
===
--- gcc.orig/gcc/config/i386/i386.c 2011-04-01 18:26:53.207236300 +0200
+++ gcc/gcc/config/i386/i386.c  2011-04-01 20:32:34.012872700 +0200
@@ -5436,6 +5436,40 @@ ix86_handle_cconv_attribute (tree *node,
   return NULL_TREE;
 }
 
+/* This function checks if the method-function has default __thiscall
+   calling-convention for 32-bit msabi.
+   It returns true if TYPE is of kind METHOD_TYPE, no stdarg function,
+   and the MS_ABI 32-bit is used.  Otherwise it returns false.  */
+
+static bool
+ix86_is_msabi_thiscall (const_tree type)
+{
+  if (TARGET_64BIT || ix86_function_type_abi (type) != MS_ABI
+  || TREE_CODE (type) != METHOD_TYPE || stdarg_p (type))
+return false;
+  /* Check for different calling-conventions.  */
+  if (lookup_attribute (cdecl, TYPE_ATTRIBUTES (type))
+  || lookup_attribute (stdcall, TYPE_ATTRIBUTES (type))
+  || lookup_attribute (fastcall, TYPE_ATTRIBUTES (type))
+  || lookup_attribute (regparm, TYPE_ATTRIBUTES (type))
+  || lookup_attribute (sseregparm, TYPE_ATTRIBUTES (type)))
+return false;
+  return true;
+}
+
+/* This function checks if the thiscall attribute is set for the TYPE,
+   or if it is an method-type with default thiscall convention.
+   It returns true if function match, otherwise false is returned.  */
+
+static bool
+ix86_is_type_thiscall (const_tree type)
+{
+  if (lookup_attribute (thiscall, TYPE_ATTRIBUTES (type))
+  || ix86_is_msabi_thiscall (type))
+return true;
+  return false;
+}
+
 /* Return 0 if the attributes for two types are incompatible, 1 if they
are compatible, and 2 if they are nearly compatible (which causes a
warning to be generated).  */
@@ -5444,7 +5478,8 @@ static int
 ix86_comp_type_attributes (const_tree type1, const_tree type2)
 {
   /* Check for mismatch of non-default calling convention.  */
-  const char *const rtdstr = TARGET_RTD ? cdecl : stdcall;
+  bool is_thiscall = ix86_is_msabi_thiscall (type1);
+  const char *const rtdstr = TARGET_RTD ? (is_thiscall ? thiscall : cdecl) 
: stdcall;
 
   if (TREE_CODE (type1) != FUNCTION_TYPE
TREE_CODE (type1) != METHOD_TYPE)
@@ -5463,9 +5498,18 @@ ix86_comp_type_attributes (const_tree ty
 return 0;
 
   /* Check for mismatched thiscall types.  */
-  if (!lookup_attribute (thiscall, TYPE_ATTRIBUTES (type1))
-  != !lookup_attribute (thiscall, TYPE_ATTRIBUTES (type2)))
-return 0;
+  if (is_thiscall  !TARGET_RTD)
+{
+  if (!lookup_attribute (cdecl, TYPE_ATTRIBUTES (type1))
+ != !lookup_attribute (cdecl, TYPE_ATTRIBUTES (type2)))
+   return 0;
+}
+  else if (!is_thiscall || TARGET_RTD)
+{
+  if (!lookup_attribute (thiscall, TYPE_ATTRIBUTES (type1))
+ != !lookup_attribute (thiscall, TYPE_ATTRIBUTES (type2)))
+   return 0;
+}
 
   /* Check for mismatched return types (cdecl vs stdcall).  */
   if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
@@ -5500,7 +5544,7 @@ ix86_function_regparm (const_tree type,
   if (lookup_attribute (fastcall, TYPE_ATTRIBUTES (type)))
 return 2;
 
-  if (lookup_attribute (thiscall, TYPE_ATTRIBUTES (type)))
+  if (ix86_is_type_thiscall (type))
 return 1;
 
   /* Use register calling convention for local functions when possible.  */
@@ -5666,7 +5710,7 @@ ix86_return_pops_args (tree fundecl, tre
  variable args.  */
   if (lookup_attribute (stdcall, TYPE_ATTRIBUTES (funtype))
  || lookup_attribute (fastcall, TYPE_ATTRIBUTES (funtype))
-  || lookup_attribute (thiscall, TYPE_ATTRIBUTES (funtype)))
+  || ix86_is_type_thiscall (funtype))
rtd = 1;
 
   if (rtd  ! stdarg_p (funtype))
@@ -6004,7 +6048,7 @@ init_cumulative_args (CUMULATIVE_ARGS *c
 else look for regparm information.  */
   if (fntype)
{
- if (lookup_attribute (thiscall, TYPE_ATTRIBUTES (fntype)))
+ if (ix86_is_type_thiscall (fntype))
{
  cum-nregs = 1;
  cum

Re: [patch i386]: Set for method-functions default calling-convention to thiscall for 32-bit msabi

2011-04-02 Thread Kai Tietz
2011/4/1 Richard Henderson r...@redhat.com:
 On 04/01/2011 11:36 AM, Kai Tietz wrote:
 It might be a good thing to extract those call-abi lookups into a
 specific function, which returns numbers for the selected on. By this
 we can avoid double lookup of attributes here.
 But I would like to do this in a separate patch.

 Sure.


 r~


Committed at revision 171890.

Thanks,
Kai


Re: [patch i386]: Set for method-functions default calling-convention to thiscall for 32-bit msabi

2011-04-02 Thread Kai Tietz
2011/4/2 H.J. Lu hjl.to...@gmail.com:
 On Sat, Apr 2, 2011 at 10:09 AM, Kai Tietz ktiet...@googlemail.com wrote:
 2011/4/1 Richard Henderson r...@redhat.com:
 On 04/01/2011 11:36 AM, Kai Tietz wrote:
 It might be a good thing to extract those call-abi lookups into a
 specific function, which returns numbers for the selected on. By this
 we can avoid double lookup of attributes here.
 But I would like to do this in a separate patch.

 Sure.


 r~


 Committed at revision 171890.


 This caused:

 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48416

 You changed ix86_function_arg_boundary:

 @@ -7441,8 +7485,10 @@ ix86_function_arg_boundary (enum machine_mode
 mode, const_tree type)
          warned = true;
          inform (input_location,
                  The ABI for passing parameters with %d-byte
 -                  alignment has changed in GCC 4.6,
 -                 align / BITS_PER_UNIT);
 +                  alignment has changed in GCC 4.6 (mode:%u, %d saved,
 +                 align / BITS_PER_UNIT,
 +                 ix86_compat_function_arg_boundary (mode, type, saved_align),
 +                 mode, saved_align);
        }
     }


 But it isn't mentioned in ChangeLog nor your submission. Did you check it
 in by accident?

Ups, yes. I'll correct it immediately

Kai


Re: [patch ada]: Fix MSG_WAITALL handling for windows native targets

2011-04-04 Thread Kai Tietz
2011/4/4 Thomas Quinot qui...@adacore.com:
 * Kai Tietz, 2011-04-04 :

 So here is the patch without the part in g-socthi-mingw.adb.

 Thanks, OK for me.

 --
 Thomas Quinot, Ph.D. ** qui...@adacore.com ** Senior Software Engineer
               AdaCore -- Paris, France -- New York, USA


Committed at revision 171926 to trunk.

Thanks,
Kai


[patch ada]: Last fix for PR ada/47163 on windows native hosts

2011-04-04 Thread Kai Tietz
Hello,

as described in PR, there is a failure to copy adainclude/adalib
libraries in MSYS.
This is caused by LN_S set to cp -p for MSYS. This option for cp is
not suitable to copy folder to folder in MSYS, and the additional
option -r is necessary.

ChangeLog

2011-04-04  Kai Tietz

PR ada/47163
* gcc-interface/Makefile.in (LN_S): Use additional -r option
for cp in MSYS.

Ok for apply?

Regards,
Kai

Index: Makefile.in
===
--- Makefile.in (revision 171925)
+++ Makefile.in (working copy)
@@ -1461,7 +1461,7 @@
 soext  = .exe
 hyphen = _
 LN = cp -p
-LN_S = cp -p
+LN_S = cp -pr

 .SUFFIXES: .sym


Re: [patch ada]: Last fix for PR ada/47163 on windows native hosts

2011-04-05 Thread Kai Tietz
2011/4/5 Arnaud Charlet char...@adacore.com:
 as described in PR, there is a failure to copy adainclude/adalib
 libraries in MSYS.

 The PR does not give any details as to what exact error message you are
 getting, at which step, and what Makefile rule/line is causing this behavior.

 I'm surprised by LN_S is used to link directories,this looks unexpected to
 me at first sight, and first needs to be investigateed/clarified before
 deciding on a proper fix.

 Arno


Hmm, AFAICS is in Mafile.in the following line present:

# Copy target independent sources
$(foreach f,$(ADA_INCLUDE_SRCS) $(LIBGNAT_SRCS), \
  $(LN_S) $(fsrcpfx)ada/$(f) $(RTSDIR) ;) true

which seems to me the cause for this patch.

Kai


Re: [patch ada]: Last fix for PR ada/47163 on windows native hosts

2011-04-05 Thread Kai Tietz
2011/4/5 Arnaud Charlet char...@adacore.com:
 I agree, and I read the threads about that there on mingw.org.  I
 don't see a good chance that it get fixed soon there.  Nevertheless is
 the msys-environment the only way to do a full bootstrap of native gcc
 toolchain, so I would simply love to have this work-a-rounded it in
 gcc.  But well, I won't die if it isn't. ;)

 You can use other environments (e.g. cygwin or interix) to build native
 gcc under Windows, with a bit of tweaking.

I know about that. And in fact I am use Wine for doing an native
compile. Nevertheless most users using msys for native windows.  Btw
that it would work on cygwin is more theory, as you need to replace
here system's make ... but well, I admit, if I tweak enough, its
possible. Interix is another nice approach, but for most people simply
unavailable due you need more then a windows-standard edition to use
it for free.

 Yes, understood. But some lines down in Makefile we use LN_S with same
 pathes, but with filenames on all two arguments.  So I think this fear
 might be without reason here. (see section Copy new target dependent
 sources).

 The section you are referring to concerns a different and much smaller set
 of files, so will not be affected by command line limitations, so this is not
 comparable.

Sorry, here I am a bit curious. Maybe I am just unaware, but what have
the arguments of the LN_S call to do with the amount of entries in the
list, which are getting enumerated by foreach? The $f variable anyway
will contain just one filename, isn't it? Is such an foreach loop
unrolled before execution so that I have 'elements-in-foreach' *
'size-of-executed-command'?

Kai


Re: [patch libjava]: Do some fixes for windows native targets

2011-04-06 Thread Kai Tietz
2011/4/5 Tom Tromey tro...@redhat.com:
 Kai == Kai Tietz ktiet...@googlemail.com writes:

 Kai this patch fixes some issues in libjava for windows targets.  It
 Kai addresses for now only 32-bit target, but for JNICALL definition I
 Kai introduced already logic for 64-bit windows target too as preparation.

 Most of this seems ok to me.

 Kai    * java/lang/reflect/Field.h (_Jv_JNI_ToReflectedField):
 Kai    Likewise.
 Kai    * java/lang/reflect/Constructor.h (_Jv_JNI_ToReflectedMethod):
 Kai    Likewise.

 These headers are generated.  You have to edit headers.txt and then
 rebuild them.

 Tom


Hi Tom,

I added to headers.txt the changes and regenerate headers.  Btw it is
a bit tricky to enable for libjava the maintainer-mode and then have a
successful configure for it ...

ChangeLog

2011-04-06  Kai Tietz

* configure.ac (libgcj_ld_export_all): Set for windows
native targets to export-all-symbols.
(LIBGCJ_LD_EXPORT_ALL): Export libgcj_ld_export_all.
* Makefile.am (libgcj_la_LDFLAGS): Add LIBGCJ_LD_EXPORT_ALL.
* sysdep/i386/backtrace.h (MAIN_FUNC): Define for windows
native targets to DllMain.
* gcj/javaprims.h (JNICALL): Define it dependent
for different windows targets.
* include/jni_md.h: Likewise.
* headers.txt (_Jv_JNI_ToReflectedField): Mark
JNICALLS for friends.
(_Jv_JNI_ToReflectedMethod): Likewise.
* java/lang/Class.h: Regenerated.
* java/lang/reflect/Field.h: Regenerated.
* java/lang/reflect/Constructor.h: Regenerated.
* configure: Regenerated.
* Makefile.in: Regenerated.
* include/Makefile.in: Regenerated.
* testsuite/Makefile.in: Regenerated.
* gcj/Makefile.in: Regenerated.

Ok for apply?

Regards,
Kai
Index: gcc-head/libjava/Makefile.am
===
--- gcc-head.orig/libjava/Makefile.am
+++ gcc-head/libjava/Makefile.am
@@ -492,7 +492,7 @@ xlib_nat_files = $(xlib_nat_source_files
 libgcj_la_LDFLAGS = -rpath $(toolexeclibdir) $(THREADLDFLAGS) $(extra_ldflags) 
$(THREADLIBS) \
$(LIBLTDL) $(SYS_ZLIBS) $(LIBJAVA_LDFLAGS_NOUNDEF) \
-version-info `grep -v '^\#' $(srcdir)/libtool-version` \
-   $(LIBGCJ_LD_SYMBOLIC_FUNCTIONS)
+   $(LIBGCJ_LD_SYMBOLIC_FUNCTIONS) $(LIBGCJ_LD_EXPORT_ALL)
 libgcj_la_LIBADD = \
classpath/native/fdlibm/libfdlibm.la \
java/lang/Object.lo \
Index: gcc-head/libjava/configure.ac
===
--- gcc-head.orig/libjava/configure.ac
+++ gcc-head/libjava/configure.ac
@@ -214,6 +214,16 @@ if test -z $libgcj_ld_symbolic; then
   libgcj_ld_symbolic=$SYMBOLIC_LDFLAGS
 fi
 
+# for windows native targets enforce export of all symbols for shared libgcj.
+libgcj_ld_export_all=
+case $host in
+  *mingw*)
+   libgcj_ld_export_all=-Wl,--export-all-symbols
+   ;;
+  *)
+;;
+esac
+
 LIBGCJ_CFLAGS=${libgcj_cflags}
 LIBGCJ_CXXFLAGS=${libgcj_cxxflags}
 LIBGCJ_JAVAFLAGS=${libgcj_javaflags}
@@ -221,6 +231,7 @@ LIBGCJ_SUBLIB_LTFLAGS=${libgcj_sublib_l
 LIBGCJ_SUBLIB_CORE_EXTRA_DEPS=${libgcj_sublib_core_extra_deps}
 LIBGCJ_LD_SYMBOLIC=${libgcj_ld_symbolic}
 LIBGCJ_LD_SYMBOLIC_FUNCTIONS=${libgcj_ld_symbolic_functions}
+LIBGCJ_LD_EXPORT_ALL=${libgcj_ld_export_all}
 AC_SUBST(LIBGCJ_CFLAGS)
 AC_SUBST(LIBGCJ_CXXFLAGS)
 AC_SUBST(LIBGCJ_JAVAFLAGS)
@@ -228,6 +239,7 @@ AC_SUBST(LIBGCJ_SUBLIB_LTFLAGS)
 AC_SUBST(LIBGCJ_SUBLIB_CORE_EXTRA_DEPS)
 AC_SUBST(LIBGCJ_LD_SYMBOLIC)
 AC_SUBST(LIBGCJ_LD_SYMBOLIC_FUNCTIONS)
+AC_SUBST(LIBGCJ_LD_EXPORT_ALL)
 
 # Only use libltdl for non-newlib builds.
 if test x${with_newlib} = x || test x${with_newlib} = xno; then
@@ -930,6 +942,9 @@ arm*linux*eabi)
 *-*-cygwin)
 extra_ldflags_libjava=-liconv
 ;;
+*-*-mingw*)
+extra_ldflags_libjava=-lws2_32
+;;
 esac
 
 LIBMATHSPEC=
Index: gcc-head/libjava/gcj/javaprims.h
===
--- gcc-head.orig/libjava/gcj/javaprims.h
+++ gcc-head/libjava/gcj/javaprims.h
@@ -26,6 +26,15 @@ details.  */
 #undef FALSE
 #define FALSE FALSE
 
+// JNI calling convention also defined in jni.h  */
+#ifndef JNICALL
+ #if (defined (_WIN32) || defined (__WIN32__) || defined (WIN32))  !defined 
(_WIN64)
+  #define JNICALL __stdcall
+ #else
+  #define JNICALL
+ #endif
+#endif
+
 // To force selection of correct types that will mangle consistently
 // across platforms.
 extern Java
Index: gcc-head/libjava/headers.txt
===
--- gcc-head.orig/libjava/headers.txt
+++ gcc-head/libjava/headers.txt
@@ -41,26 +41,26 @@ friend jstring (::_Jv_AllocString) (jsiz
 
 class java/lang/reflect/Constructor
 prepend jmethodID _Jv_FromReflectedConstructor 
(java::lang::reflect::Constructor *);
-prepend jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID, 
jboolean);
+prepend jobject JNICALL

Re: [patch libjava]: Do some fixes for windows native targets

2011-04-06 Thread Kai Tietz
2011/4/6 Kai Tietz ktiet...@googlemail.com:
 2011/4/5 Tom Tromey tro...@redhat.com:
 Kai == Kai Tietz ktiet...@googlemail.com writes:

 Kai this patch fixes some issues in libjava for windows targets.  It
 Kai addresses for now only 32-bit target, but for JNICALL definition I
 Kai introduced already logic for 64-bit windows target too as preparation.

 Most of this seems ok to me.

 Kai    * java/lang/reflect/Field.h (_Jv_JNI_ToReflectedField):
 Kai    Likewise.
 Kai    * java/lang/reflect/Constructor.h (_Jv_JNI_ToReflectedMethod):
 Kai    Likewise.

 These headers are generated.  You have to edit headers.txt and then
 rebuild them.

 Tom


 Hi Tom,

 I added to headers.txt the changes and regenerate headers.  Btw it is
 a bit tricky to enable for libjava the maintainer-mode and then have a
 successful configure for it ...

 ChangeLog

 2011-04-06  Kai Tietz

        * configure.ac (libgcj_ld_export_all): Set for windows
        native targets to export-all-symbols.
        (LIBGCJ_LD_EXPORT_ALL): Export libgcj_ld_export_all.
        * Makefile.am (libgcj_la_LDFLAGS): Add LIBGCJ_LD_EXPORT_ALL.
        * sysdep/i386/backtrace.h (MAIN_FUNC): Define for windows
        native targets to DllMain.
        * gcj/javaprims.h (JNICALL): Define it dependent
        for different windows targets.
        * include/jni_md.h: Likewise.
        * headers.txt (_Jv_JNI_ToReflectedField): Mark
        JNICALLS for friends.
        (_Jv_JNI_ToReflectedMethod): Likewise.
        * java/lang/Class.h: Regenerated.
        * java/lang/reflect/Field.h: Regenerated.
        * java/lang/reflect/Constructor.h: Regenerated.
        * configure: Regenerated.
        * Makefile.in: Regenerated.
        * include/Makefile.in: Regenerated.
        * testsuite/Makefile.in: Regenerated.
        * gcj/Makefile.in: Regenerated.

 Ok for apply?

 Regards,
 Kai


Sorry, found a typo. Updated patch attached.

Kai
Index: gcc-head/libjava/Makefile.am
===
--- gcc-head.orig/libjava/Makefile.am
+++ gcc-head/libjava/Makefile.am
@@ -492,7 +492,7 @@ xlib_nat_files = $(xlib_nat_source_files
 libgcj_la_LDFLAGS = -rpath $(toolexeclibdir) $(THREADLDFLAGS) $(extra_ldflags) 
$(THREADLIBS) \
$(LIBLTDL) $(SYS_ZLIBS) $(LIBJAVA_LDFLAGS_NOUNDEF) \
-version-info `grep -v '^\#' $(srcdir)/libtool-version` \
-   $(LIBGCJ_LD_SYMBOLIC_FUNCTIONS)
+   $(LIBGCJ_LD_SYMBOLIC_FUNCTIONS) $(LIBGCJ_LD_EXPORT_ALL)
 libgcj_la_LIBADD = \
classpath/native/fdlibm/libfdlibm.la \
java/lang/Object.lo \
Index: gcc-head/libjava/configure.ac
===
--- gcc-head.orig/libjava/configure.ac
+++ gcc-head/libjava/configure.ac
@@ -214,6 +214,16 @@ if test -z $libgcj_ld_symbolic; then
   libgcj_ld_symbolic=$SYMBOLIC_LDFLAGS
 fi
 
+# for windows native targets enforce export of all symbols for shared libgcj.
+libgcj_ld_export_all=
+case $host in
+  *mingw*)
+   libgcj_ld_export_all=-Wl,--export-all-symbols
+   ;;
+  *)
+;;
+esac
+
 LIBGCJ_CFLAGS=${libgcj_cflags}
 LIBGCJ_CXXFLAGS=${libgcj_cxxflags}
 LIBGCJ_JAVAFLAGS=${libgcj_javaflags}
@@ -221,6 +231,7 @@ LIBGCJ_SUBLIB_LTFLAGS=${libgcj_sublib_l
 LIBGCJ_SUBLIB_CORE_EXTRA_DEPS=${libgcj_sublib_core_extra_deps}
 LIBGCJ_LD_SYMBOLIC=${libgcj_ld_symbolic}
 LIBGCJ_LD_SYMBOLIC_FUNCTIONS=${libgcj_ld_symbolic_functions}
+LIBGCJ_LD_EXPORT_ALL=${libgcj_ld_export_all}
 AC_SUBST(LIBGCJ_CFLAGS)
 AC_SUBST(LIBGCJ_CXXFLAGS)
 AC_SUBST(LIBGCJ_JAVAFLAGS)
@@ -228,6 +239,7 @@ AC_SUBST(LIBGCJ_SUBLIB_LTFLAGS)
 AC_SUBST(LIBGCJ_SUBLIB_CORE_EXTRA_DEPS)
 AC_SUBST(LIBGCJ_LD_SYMBOLIC)
 AC_SUBST(LIBGCJ_LD_SYMBOLIC_FUNCTIONS)
+AC_SUBST(LIBGCJ_LD_EXPORT_ALL)
 
 # Only use libltdl for non-newlib builds.
 if test x${with_newlib} = x || test x${with_newlib} = xno; then
@@ -930,6 +942,9 @@ arm*linux*eabi)
 *-*-cygwin)
 extra_ldflags_libjava=-liconv
 ;;
+*-*-mingw*)
+extra_ldflags_libjava=-lws2_32
+;;
 esac
 
 LIBMATHSPEC=
Index: gcc-head/libjava/gcj/javaprims.h
===
--- gcc-head.orig/libjava/gcj/javaprims.h
+++ gcc-head/libjava/gcj/javaprims.h
@@ -26,6 +26,15 @@ details.  */
 #undef FALSE
 #define FALSE FALSE
 
+// JNI calling convention also defined in jni.h  */
+#ifndef JNICALL
+ #if (defined (_WIN32) || defined (__WIN32__) || defined (WIN32))  !defined 
(_WIN64)
+  #define JNICALL __stdcall
+ #else
+  #define JNICALL
+ #endif
+#endif
+
 // To force selection of correct types that will mangle consistently
 // across platforms.
 extern Java
Index: gcc-head/libjava/headers.txt
===
--- gcc-head.orig/libjava/headers.txt
+++ gcc-head/libjava/headers.txt
@@ -41,26 +41,26 @@ friend jstring (::_Jv_AllocString) (jsiz
 
 class java/lang/reflect/Constructor
 prepend jmethodID _Jv_FromReflectedConstructor 
(java::lang::reflect::Constructor *);
-prepend jobject

[patch i386]: Cleanup calling convention handling in i386.c and fix PR target/9601 and PR target/11772

2011-04-07 Thread Kai Tietz
Hello,

This patch cleans up a bit the calling convention checking in i386
architecture.  By this
I could fix some pretty old bugs about the -mrtd option. See as reference
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11772
and http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9601

For none-prototyped function calls nowadays the linker is able to do
the stdcall fixup
successful (avoiding warning via -Wl,--enable-stdcall-fixup). So we
emit for this case
just the undecorated function's symbol name.

ChangeLog

2011-04-07  Kai Tietz

PR target/9601
PR target/11772
* config/i386/i386-protos.h (ix86_get_callcvt): New prototype.
* config/i386/i386.c (ix86_handle_cconv_attribute): Adjust
comment.
(ix86_is_msabi_thiscall): Removed.
(ix86_is_type_thiscall): Likewise.
(ix86_get_callcvt): New function.
(ix86_comp_type_attributes): Simplify check.
(ix86_function_regparm): Use ix86_get_callcvt for calling
convention attribute checks.
(ix86_return_pops_args): Likewise.
(ix86_static_chain): Likewise.
(x86_this_parameter): Likewise.
(x86_output_mi_thunk): Likewise.
* config/i386/i386.h (IX86_CALLCVT_CDECL, IX86_CALLCVT_STDCALL,
IX86_CALLCVT_FASTCALL, IX86_CALLCVT_THISCALL, IX86_CALLCVT_REGPARM,
IX86_CALLCVT_SSEREGPARM): New macros to represent calling convention
by flag-values.
(IX86_BASE_CALLCVT): Helper macro.
* config/i386/netware.c (i386_nlm_maybe_mangle_decl_assembler_name):
Use ix86_get_callcvt for calling convention attribute checks.
* config/i386/winnt.c (i386_pe_maybe_mangle_decl_assembler_name):
Likewise.
(gen_stdcall_or_fastcall_suffix): Handle TARGET_RTD case for
none-prototyped function calls.

Tested for i686-w64-mingw32, x86_64-w64-mingw32, and
x86_64-pc-linux-gnu. Ok for apply?

Regards,
Kai
Index: gcc/gcc/config/i386/i386-protos.h
===
--- gcc.orig/gcc/config/i386/i386-protos.h  2011-01-13 20:55:30.0 
+0100
+++ gcc/gcc/config/i386/i386-protos.h   2011-04-07 11:02:16.645985200 +0200
@@ -191,6 +191,8 @@ extern tree ix86_handle_shared_attribute
 extern tree ix86_handle_selectany_attribute (tree *, tree, tree, int, bool *);
 extern int x86_field_alignment (tree, int);
 extern tree ix86_valid_target_attribute_tree (tree);
+extern unsigned int ix86_get_callcvt (const_tree);
+
 #endif
 
 extern rtx ix86_tls_get_addr (void);
Index: gcc/gcc/config/i386/i386.c
===
--- gcc.orig/gcc/config/i386/i386.c 2011-04-06 19:13:30.0 +0200
+++ gcc/gcc/config/i386/i386.c  2011-04-07 14:51:22.411975800 +0200
@@ -5312,7 +5312,7 @@ ix86_handle_cconv_attribute (tree *node,
   return NULL_TREE;
 }
 
-  /* Can combine regparm with all attributes but fastcall.  */
+  /* Can combine regparm with all attributes but fastcall, and thiscall.  */
   if (is_attribute_p (regparm, name))
 {
   tree cst;
@@ -5436,38 +5436,50 @@ ix86_handle_cconv_attribute (tree *node,
   return NULL_TREE;
 }
 
-/* This function checks if the method-function has default __thiscall
-   calling-convention for 32-bit msabi.
-   It returns true if TYPE is of kind METHOD_TYPE, no stdarg function,
-   and the MS_ABI 32-bit is used.  Otherwise it returns false.  */
+/* This function determines from TYPE the calling-convention.  */
 
-static bool
-ix86_is_msabi_thiscall (const_tree type)
+unsigned int
+ix86_get_callcvt (const_tree type)
 {
-  if (TARGET_64BIT || ix86_function_type_abi (type) != MS_ABI
-  || TREE_CODE (type) != METHOD_TYPE || stdarg_p (type))
-return false;
-  /* Check for different calling-conventions.  */
-  if (lookup_attribute (cdecl, TYPE_ATTRIBUTES (type))
-  || lookup_attribute (stdcall, TYPE_ATTRIBUTES (type))
-  || lookup_attribute (fastcall, TYPE_ATTRIBUTES (type))
-  || lookup_attribute (regparm, TYPE_ATTRIBUTES (type))
-  || lookup_attribute (sseregparm, TYPE_ATTRIBUTES (type)))
-return false;
-  return true;
-}
+  unsigned int ret = 0;
 
-/* This function checks if the thiscall attribute is set for the TYPE,
-   or if it is an method-type with default thiscall convention.
-   It returns true if function match, otherwise false is returned.  */
+  if (TARGET_64BIT)
+return IX86_CALLCVT_CDECL;
 
-static bool
-ix86_is_type_thiscall (const_tree type)
-{
-  if (lookup_attribute (thiscall, TYPE_ATTRIBUTES (type))
-  || ix86_is_msabi_thiscall (type))
-return true;
-  return false;
+  if (lookup_attribute (cdecl, TYPE_ATTRIBUTES (type)))
+ret |= IX86_CALLCVT_CDECL;
+  else if (lookup_attribute (stdcall, TYPE_ATTRIBUTES (type)))
+ret |= IX86_CALLCVT_STDCALL;
+  else if (lookup_attribute (fastcall, TYPE_ATTRIBUTES (type)))
+ret |= IX86_CALLCVT_FASTCALL;
+  else if (lookup_attribute (thiscall, TYPE_ATTRIBUTES (type)))
+ret

Re: [patch libjava]: Do some fixes for windows native targets

2011-04-08 Thread Kai Tietz
2011/4/8 Tom Tromey tro...@redhat.com:
 Kai == Kai Tietz ktiet...@googlemail.com writes:

 Kai I added to headers.txt the changes and regenerate headers.  Btw it is
 Kai a bit tricky to enable for libjava the maintainer-mode and then have a
 Kai successful configure for it ...

 [...]

 Kai Sorry, found a typo. Updated patch attached.

 This is ok.  Thanks.

 Tom


Applied at revision 172186.

Kai


Re: [patch i386]: Cleanup calling convention handling in i386.c and fix PR target/9601 and PR target/11772

2011-04-09 Thread Kai Tietz
2011/4/8 Richard Henderson r...@redhat.com:
 +  /* Special case regparm/sseregparm, which are either cdecl or stdcall.  */
 +  if ((ret  (IX86_CALLCVT_REGPARM | IX86_CALLCVT_SSEREGPARM)) != 0)
 +    return (ret | ((TARGET_RTD  !stdarg_p (type)) ? IX86_CALLCVT_STDCALL
 +                                                   : IX86_CALLCVT_CDECL));
 +
 +  /* We don't have found a default call-convention specifier,
 +     so apply default.  */
 +  if (TARGET_RTD  !stdarg_p (type))
 +    return IX86_CALLCVT_STDCALL;
 +  else if (TREE_CODE (type) != METHOD_TYPE || stdarg_p (type)
 +          || ix86_function_type_abi (type) != MS_ABI)
 +    return IX86_CALLCVT_CDECL;
 +  return IX86_CALLCVT_THISCALL;

 Perhaps clearer as

  bool stdarg = stdarg_p (type);

  if (TARGET_RTD  !stdarg)
    return IX86_CALLCVT_STDCALL | ret;

  if (ret != 0
      || stdarg
      || TREE_CODE (type) != METHOD_TYPE
      || ix86_function_type_abi (type) != MS_ABI)
    return IX86_CALLCVT_CDECL | ret;

  return IX86_CALLCVT_THISCALL;

Yes, patch adjusted for this.

 +    case IX86_CALLCVT_STDCALL:
 +    case IX86_CALLCVT_FASTCALL:
 +    case IX86_CALLCVT_THISCALL:
 +      rtd = 1;
 +      break;
      }

 +  if (rtd  ! stdarg_p (funtype))
 +    return size;

 You can move the stdarg_p test into the switch and drop the rtd variable.

Rewrote switch so that just an if is used and the rtd variable isn't
necessary anymore.

 +  if ((ccvt  IX86_CALLCVT_STDCALL) != 0)
      new_id = gen_stdcall_or_fastcall_decoration (decl, id, '_');
 +  else if (ccvt == IX86_CALLCVT_FASTCALL)
      new_id = gen_stdcall_or_fastcall_decoration (decl, id, FASTCALL_PREFIX);

 I think perhaps it would be cleaner to consistently test bits,
 rather than sometimes test bits and sometimes test equality.
 I know that FASTCALL isn't supposed to have any other bits set,
 but we shouldn't have to constantly think about which is which.

 Not just here in netware.c, where I noticed, but elsewhere as well.

Ok, changed comparison by bit-tests.

2011-04-09  Kai Tietz

PR target/9601
PR target/11772
* config/i386/i386-protos.h (ix86_get_callcvt): New prototype.
* config/i386/i386.c (ix86_handle_cconv_attribute): Adjust
comment.
(ix86_is_msabi_thiscall): Removed.
(ix86_is_type_thiscall): Likewise.
(ix86_get_callcvt): New function.
(ix86_comp_type_attributes): Simplify check.
(ix86_function_regparm): Use ix86_get_callcvt for calling
convention attribute checks.
(ix86_return_pops_args): Likewise.
(ix86_static_chain): Likewise.
(x86_this_parameter): Likewise.
(x86_output_mi_thunk): Likewise.
(ix86_function_type_abi): Optimize check for types without attributes.
* config/i386/i386.h (IX86_CALLCVT_CDECL, IX86_CALLCVT_STDCALL,
IX86_CALLCVT_FASTCALL, IX86_CALLCVT_THISCALL, IX86_CALLCVT_REGPARM,
IX86_CALLCVT_SSEREGPARM): New macros to represent calling convention
by flag-values.
(IX86_BASE_CALLCVT): Helper macro.
* config/i386/netware.c (i386_nlm_maybe_mangle_decl_assembler_name):
Use ix86_get_callcvt for calling convention attribute checks and avoid
symbol-decoration for stdcall in TARGET_RTD case.
* config/i386/winnt.c (i386_pe_maybe_mangle_decl_assembler_name):
Likewise.
(gen_stdcall_or_fastcall_suffix): Adjust ident and use DECL_ORIGIN
for declaration.

Regards,
Kai
Index: gcc/gcc/config/i386/i386-protos.h
===
--- gcc.orig/gcc/config/i386/i386-protos.h  2011-04-08 16:00:16.264411500 
+0200
+++ gcc/gcc/config/i386/i386-protos.h   2011-04-09 12:38:15.360805300 +0200
@@ -191,6 +191,8 @@ extern tree ix86_handle_shared_attribute
 extern tree ix86_handle_selectany_attribute (tree *, tree, tree, int, bool *);
 extern int x86_field_alignment (tree, int);
 extern tree ix86_valid_target_attribute_tree (tree);
+extern unsigned int ix86_get_callcvt (const_tree);
+
 #endif
 
 extern rtx ix86_tls_get_addr (void);
Index: gcc/gcc/config/i386/i386.c
===
--- gcc.orig/gcc/config/i386/i386.c 2011-04-08 16:00:16.272411500 +0200
+++ gcc/gcc/config/i386/i386.c  2011-04-09 14:01:32.239610400 +0200
@@ -5312,7 +5312,7 @@ ix86_handle_cconv_attribute (tree *node,
   return NULL_TREE;
 }
 
-  /* Can combine regparm with all attributes but fastcall.  */
+  /* Can combine regparm with all attributes but fastcall, and thiscall.  */
   if (is_attribute_p (regparm, name))
 {
   tree cst;
@@ -5436,38 +5436,54 @@ ix86_handle_cconv_attribute (tree *node,
   return NULL_TREE;
 }
 
-/* This function checks if the method-function has default __thiscall
-   calling-convention for 32-bit msabi.
-   It returns true if TYPE is of kind METHOD_TYPE, no stdarg function,
-   and the MS_ABI 32-bit is used.  Otherwise it returns false.  */
+/* This function

Re: [patch i386]: Cleanup calling convention handling in i386.c and fix PR target/9601 and PR target/11772

2011-04-10 Thread Kai Tietz
I had introduced an const issue by recent patch. Attached patch fixes that.

Kai
Index: gcc/gcc/config/i386/i386-protos.h
===
--- gcc.orig/gcc/config/i386/i386-protos.h  2011-04-08 16:00:16.264411500 
+0200
+++ gcc/gcc/config/i386/i386-protos.h   2011-04-09 12:38:15.360805300 +0200
@@ -191,6 +191,8 @@ extern tree ix86_handle_shared_attribute
 extern tree ix86_handle_selectany_attribute (tree *, tree, tree, int, bool *);
 extern int x86_field_alignment (tree, int);
 extern tree ix86_valid_target_attribute_tree (tree);
+extern unsigned int ix86_get_callcvt (const_tree);
+
 #endif
 
 extern rtx ix86_tls_get_addr (void);
Index: gcc/gcc/config/i386/i386.c
===
--- gcc.orig/gcc/config/i386/i386.c 2011-04-08 16:00:16.272411500 +0200
+++ gcc/gcc/config/i386/i386.c  2011-04-09 19:31:13.991227800 +0200
@@ -5312,7 +5312,7 @@ ix86_handle_cconv_attribute (tree *node,
   return NULL_TREE;
 }
 
-  /* Can combine regparm with all attributes but fastcall.  */
+  /* Can combine regparm with all attributes but fastcall, and thiscall.  */
   if (is_attribute_p (regparm, name))
 {
   tree cst;
@@ -5436,38 +5436,54 @@ ix86_handle_cconv_attribute (tree *node,
   return NULL_TREE;
 }
 
-/* This function checks if the method-function has default __thiscall
-   calling-convention for 32-bit msabi.
-   It returns true if TYPE is of kind METHOD_TYPE, no stdarg function,
-   and the MS_ABI 32-bit is used.  Otherwise it returns false.  */
+/* This function determines from TYPE the calling-convention.  */
 
-static bool
-ix86_is_msabi_thiscall (const_tree type)
+unsigned int
+ix86_get_callcvt (const_tree type)
 {
-  if (TARGET_64BIT || ix86_function_type_abi (type) != MS_ABI
-  || TREE_CODE (type) != METHOD_TYPE || stdarg_p (type))
-return false;
-  /* Check for different calling-conventions.  */
-  if (lookup_attribute (cdecl, TYPE_ATTRIBUTES (type))
-  || lookup_attribute (stdcall, TYPE_ATTRIBUTES (type))
-  || lookup_attribute (fastcall, TYPE_ATTRIBUTES (type))
-  || lookup_attribute (regparm, TYPE_ATTRIBUTES (type))
-  || lookup_attribute (sseregparm, TYPE_ATTRIBUTES (type)))
-return false;
-  return true;
-}
+  unsigned int ret = 0;
+  bool is_stdarg;
+  tree attrs;
 
-/* This function checks if the thiscall attribute is set for the TYPE,
-   or if it is an method-type with default thiscall convention.
-   It returns true if function match, otherwise false is returned.  */
+  if (TARGET_64BIT)
+return IX86_CALLCVT_CDECL;
 
-static bool
-ix86_is_type_thiscall (const_tree type)
-{
-  if (lookup_attribute (thiscall, TYPE_ATTRIBUTES (type))
-  || ix86_is_msabi_thiscall (type))
-return true;
-  return false;
+  attrs = TYPE_ATTRIBUTES (type);
+  if (attrs != NULL_TREE)
+{
+  if (lookup_attribute (cdecl, attrs))
+   ret |= IX86_CALLCVT_CDECL;
+  else if (lookup_attribute (stdcall, attrs))
+   ret |= IX86_CALLCVT_STDCALL;
+  else if (lookup_attribute (fastcall, attrs))
+   ret |= IX86_CALLCVT_FASTCALL;
+  else if (lookup_attribute (thiscall, attrs))
+   ret |= IX86_CALLCVT_THISCALL;
+
+  /* Regparam isn't allowed for thiscall and fastcall.  */
+  if ((ret  (IX86_CALLCVT_THISCALL | IX86_CALLCVT_FASTCALL)) == 0)
+   {
+ if (lookup_attribute (regparm, attrs))
+   ret |= IX86_CALLCVT_REGPARM;
+ if (lookup_attribute (sseregparm, attrs))
+   ret |= IX86_CALLCVT_SSEREGPARM;
+   }
+
+  if (IX86_BASE_CALLCVT(ret) != 0)
+   return ret;
+}
+
+  is_stdarg = stdarg_p (type);
+  if (TARGET_RTD  !is_stdarg)
+return IX86_CALLCVT_STDCALL | ret;
+
+  if (ret != 0
+  || is_stdarg
+  || TREE_CODE (type) != METHOD_TYPE
+  || ix86_function_type_abi (type) != MS_ABI)
+return IX86_CALLCVT_CDECL | ret;
+
+  return IX86_CALLCVT_THISCALL;
 }
 
 /* Return 0 if the attributes for two types are incompatible, 1 if they
@@ -5477,43 +5493,18 @@ ix86_is_type_thiscall (const_tree type)
 static int
 ix86_comp_type_attributes (const_tree type1, const_tree type2)
 {
-  /* Check for mismatch of non-default calling convention.  */
-  bool is_thiscall = ix86_is_msabi_thiscall (type1);
-  const char *const rtdstr = TARGET_RTD ? (is_thiscall ? thiscall : cdecl) 
: stdcall;
+  unsigned int ccvt1, ccvt2;
 
   if (TREE_CODE (type1) != FUNCTION_TYPE
TREE_CODE (type1) != METHOD_TYPE)
 return 1;
 
-  /* Check for mismatched fastcall/regparm types.  */
-  if ((!lookup_attribute (fastcall, TYPE_ATTRIBUTES (type1))
-   != !lookup_attribute (fastcall, TYPE_ATTRIBUTES (type2)))
-  || (ix86_function_regparm (type1, NULL)
- != ix86_function_regparm (type2, NULL)))
-return 0;
-
-  /* Check for mismatched sseregparm types.  */
-  if (!lookup_attribute (sseregparm, TYPE_ATTRIBUTES (type1))
-  != !lookup_attribute (sseregparm, TYPE_ATTRIBUTES (type2)))
+  

Re: [patch i386]: Cleanup calling convention handling in i386.c and fix PR target/9601 and PR target/11772

2011-04-11 Thread Kai Tietz
2011/4/11 Richard Henderson r...@redhat.com:
 On 04/10/2011 12:01 AM, Kai Tietz wrote:
 I had introduced an const issue by recent patch. Attached patch fixes that.

 Patch is ok.

Applied at revision 172268.

Thanks,
Kai


Re: [patch i386 mingw g++.dg gcc.dg]: Set -mms-bitfields as default for native windows targets

2011-04-12 Thread Kai Tietz
2011/4/12 Richard Henderson r...@redhat.com:
 On 04/12/2011 05:47 AM, Kai Tietz wrote:
 ChangeLog gcc/

       * config/i386/mingw32.h (TARGET_SUBTARGET_DEFAULT): Add
       MASK_MS_BITFIELD_LAYOUT bit.

 ChangeLog gcc/testsuite

       * g++.dg/ext/bitfield2.C: Add for i?86/x86_64-*-mingw*
       targets the additional -mno-ms-bitfields and
       -Wno-packed-bitfield-compat options.
       * g++.dg/ext/bitfield3.C: Likewise.
       * g++.dg/ext/bitfield4.C: Likewise.
       * g++.dg/ext/bitfield5.C: Likewise.
       * gcc.dg/bitfld-15.c: Likewise.
       * gcc.dg/bitfld-16.c: Likewise.
       * gcc.dg/bitfld-17.c: Likewise.
       * gcc.dg/bitfld-18.c: Likewise.

 Ok.


 r~



Applied at revision 172336.

Thanks,
Kai


Re: [patch i386 mingw g++.dg gcc.dg]: Set -mms-bitfields as default for native windows targets

2011-04-13 Thread Kai Tietz
2011/4/13 Pedro Alves pe...@codesourcery.com:
 On Tuesday 12 April 2011 19:53:42, Kai Tietz wrote:
 2011/4/12 Richard Henderson r...@redhat.com:
  On 04/12/2011 05:47 AM, Kai Tietz wrote:
  ChangeLog gcc/
 
        * config/i386/mingw32.h (TARGET_SUBTARGET_DEFAULT): Add
        MASK_MS_BITFIELD_LAYOUT bit.
 
  ChangeLog gcc/testsuite
 
        * g++.dg/ext/bitfield2.C: Add for i?86/x86_64-*-mingw*
        targets the additional -mno-ms-bitfields and
        -Wno-packed-bitfield-compat options.
        * g++.dg/ext/bitfield3.C: Likewise.
        * g++.dg/ext/bitfield4.C: Likewise.
        * g++.dg/ext/bitfield5.C: Likewise.
        * gcc.dg/bitfld-15.c: Likewise.
        * gcc.dg/bitfld-16.c: Likewise.
        * gcc.dg/bitfld-17.c: Likewise.
        * gcc.dg/bitfld-18.c: Likewise.
 
  Ok.
 
 
  r~
 


 Applied at revision 172336.

 Thanks,
 Kai


 This is a default ABI change (IIRC, when the option was
 introduced, it was left off as default so to not break the ABI).

 Shouldn't we advertise it somewhere?

 --
 Pedro Alves


Yes, I did recently a lot of abi changing for mingw's targets.  They
all will need a nice description (and possible ways to get old default
behavior) in changes.html

I collect them for later.  Or do you mean it should be noted earlier?

Regards,
Kai


Re: [patch tree-optimization]: Improve reassociation pass for bitwise-operations

2011-09-21 Thread Kai Tietz
Hello,

This revised patch adds support to tree-ssa-reassoc for intial
normalizing of bitwise operation.  So the reassociation pass is able
to have better folding result.
Also it has a final denormalzing of bitwise-operations after
reassociation pass is completed to restore optimized writing.

This patch is a bit huge, but I see here no good point to split it
into smaller pieces due the denormalization and normalization of
bitwise-operation are  bound pretty much to each other.

I added some additional testcases to check also for the denormalization pass.

Normalization transforms the following patterns:

 - ~ (X | Y) - ~X  ~Y
 - ~ (X  Y) - ~X | ~Y
 - ~ (X ^ Y) - ~X ^ Y
 - ~ (X ^ CST) - X ^ CST'; with CST'=~CST
 - ~ (X cmp Y) - X cmp' Y; with cmp' = inverted comparison of cmp
 - ((X cmp Y) != 0) - X cmp Y
 - ((X cmp Y) == 0) - X cmp' Y; with cmp' = inverted comparison of cmp
 - ~ (~X) - X
 - (X ! Y) != 0 - (X != 0) | (Y != 0)
 - (X | Y) == 0 - (X == 0)  (Y == 0)

by this even more complex statments like produced for this code:

  int foo (int a, int b, int c, int d)
  {
int r1 = a != 0  c != 0  b != 0;
int r2 = a == 0 | b != 0 | d == 0;
return (r1 != 0  r2 == 0);
  }

getting in gimple transformed to (as pseudo code)

return (a != 0  c != 0  b != 0  a != 0  b == 0  d != 0);

which can be optimized to fixed result of zero.


The de-normalization pass transforms the following patterns

 - ~X  ~Y - ~ (X | Y)
 - ~X  CST - ~ (X | CST'); with CST'=~CST
 - ~X | ~Y - ~ (X  Y)
 - ~X | CST - ~ (X  CST'); with CST'=~CST
 - ~X ^ Y - ~ (X ^ Y)
 - ~X ^ CST - X ^ CST'; with CST'=~CST
 - (X != 0) | (Y != 0) - (X ! Y) != 0
 - (X == 0)  (Y == 0) - (X | Y) == 0
 - (X != ~0) | (Y != ~0) - (X  Y) != ~0
 - (X == ~0)  (Y == ~0) - (X  Y) != ~0

ChangeLog

2011-09-21  Kai Tietz  kti...@redhat.com

* tree-ssa-reassoc.c (gimple build_and_add_sum): Add forwarder
declaration and add support for unary-expressions.
(remove_visited_stmt_chain): Add forwarder declaration.
(push_bitwise_op): New helper function.
(remove_bitwise_op): Likewise.
(operate_bitwise_stmt): Likewise.
(repropagate_bitwise): Likewise.
(operate_bitwise_xor_stmt): Likewise.
(make_new_tmp_statement): Likewise.
(expand_not_bitwise_binary): Likewise.
(get_bitwise_single_use_root): Likewise.
(is_bitwise_not): Likewise.
(walk_bitwise_stmt_elems): Likewise.
(expand_cmp_ior): Likewise.
(rebuild_vector_tree): Likewise.
(break_up_bitwise_combined_stmt): Likewise.
(merge_bitwise_compares): Likewise.
(bitwise_ops): New static variable.
(break_up_subtract_bb): Renamed to break_up_expr_bb and
add call to break_up_bitwise_combined_stmt function.
(do_reassoc): Rename break_up_subtract_bb call as break_up_expr_bb.
(init_reassoc): Initialize bitwise_ops vector.
(fini_reassoc): Destroy bitwise_ops vector.
(execute_reassoc): Add call for repropagate_bitwise function.


ChangeLog gcc/testsuite

2011-09-21  Kai Tietz  kti...@redhat.com

* gcc.dg/tree-ssa/reassoc-26.c: New test.
* gcc.dg/tree-ssa/reassoc-27.c: New test.
* gcc.dg/tree-ssa/reassoc-28.c: New test.
* gcc.dg/tree-ssa/reassoc-29.c: New test.
* gcc.dg/tree-ssa/reassoc-30.c: New test.
* gcc.dg/tree-ssa/reassoc-31.c: New test.
* gcc.dg/tree-ssa/reassoc-32.c: New test.
* gcc.dg/tree-ssa/reassoc-33.c: New test.
* gcc.dg/tree-ssa/reassoc-34.c: New test.
* gcc.dg/tree-ssa/reassoc-35.c: New test.

Bootstrapped and regression tested for all languages (including Ada
and Obj-C++) on host x86_64-pc-linux-gnu.
Ok for apply?

Regards,
Kai

Index: gcc/gcc/tree-ssa-reassoc.c
===
--- gcc.orig/gcc/tree-ssa-reassoc.c
+++ gcc/gcc/tree-ssa-reassoc.c
@@ -43,6 +43,10 @@ along with GCC; see the file COPYING3.
 #include target.h
 #include params.h

+/* Forwarders.  */
+static gimple build_and_add_sum (tree, tree, tree, enum tree_code);
+static void remove_visited_stmt_chain (tree);
+
 /*  This is a simple global reassociation pass.  It is, in part, based
 on the LLVM pass of the same name (They do some things more/less
 than we do, in different orders, etc).
@@ -50,7 +54,9 @@ along with GCC; see the file COPYING3.
 It consists of five steps:

 1. Breaking up subtract operations into addition + negate, where
-it would promote the reassociation of adds.
+it would promote the reassociation of adds.  Additionally breaking
+up combined expression made out of boolean-typed bitwise expressions
+for improving simplification.

 2. Left linearization of the expression trees, so that (A+B)+(C+D)
 becomes (((A+B)+C)+D), which is easier for us to rewrite later.
@@ -194,7 +200,9 @@ static struct pointer_map_t *operand_ran

 /* Forward decls.  */
 static long get_rank (tree

Re: [Mingw-users] [patch] --enable-dynamic-string default for mingw-w64

2011-09-25 Thread Kai Tietz
2011/9/25 Paolo Carlini paolo.carl...@oracle.com:
 On 09/25/2011 05:14 PM, Cesar Strauss wrote:

 I quote my reasoning: On 09/20/2011 11:56 PM, Cesar Strauss wrote:

 On the one hand, according to comment 4 of [1], by using
 --enable-fully-dynamic-string, all other users will miss a very good
 optimization. On the other hand, these users of -static-libstdc++ are
 mixing shared and static libraries, which isn't a good idea in
 general anyway, is it?

 [1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24196

 If you ask me, I totally agree. But I don't maintain any mingw target, thus,
 **if** the target maintainers want to do something like that I provided info
 about the correct way to do it.

 Paolo.

I see Cesar's point, and so my vote is for enabling it for w64 flavor
only. We providing users the ability to build with static and want to
avoid at least obvious issues here.  I admit that people might mix
here static and shared libraries, but that's in fact then more an
issue of wrong use, which can be clarified by user-documentation for
mingw-w64.

Thanks Paolo for offering information for JonY for doing this the
right way in libstdc++.

Regards,
Kai


Re: [google] Add SECTION_EXCLUDE flag and exclude .gnu.callgraph sections (issue5126041)

2011-09-27 Thread Kai Tietz
2011/9/27 Richard Henderson r...@redhat.com:
 On 09/23/2011 04:45 PM, Sriraman Tallam wrote:
 I also want the SECTION_EXCLUDE part alone to be considered for trunk.

 This is ok for trunk.

 Kai, is there a similar flag for pe-coff?  I.e. is there something
 reasonable that we can add to i386_pe_asm_named_section?

Well, pe-coff also has SEC_EXCLUDE.  Its meaning is that the section
gets discarded on linking.  I checked in gas/config/obj-coff.c and
there is right now AFAICS no way to specify this flag for a section.
But it should be trivial to add it there with specifier 'e'.

Kai


[patch windows]: Support SECTION_EXCLUDE for pe-coff targets

2011-09-27 Thread Kai Tietz
Hi,

this patch enables same feature as in thread [google] Add
SECTION_EXCLUDE flag and exclude .gnu.callgraph sections
(issue5126041) for pe-coff x86 and x64 targets.

ChangeLog

2011-09-27  Kai Tietz  kti...@redhat.com

* configure.ac: Add test for new section attribute
specifier e via define HAVE_GAS_SECTION_EXCLUDE.
* config.in: Regenerated.
* configure: Regenerated.
* config/i386/winnt.c (i386_pe_asm_named_section): Emit
new section flag e for excluded sections, if supported.

Tested for x86_64-w64-mingw32, i686-w64-mingw32, and i686-pc-cygwin.
Ok for apply?

Index: gcc/gcc/config/i386/winnt.c
===
--- gcc.orig/gcc/config/i386/winnt.c
+++ gcc/gcc/config/i386/winnt.c
@@ -484,6 +484,11 @@ i386_pe_asm_named_section (const char *n
 {
   char flagchars[8], *f = flagchars;

+#ifdef HAVE_GAS_SECTION_EXCLUDE
+  if ((flags  SECTION_EXCLUDE) != 0)
+*f++ = 'e';
+#endif
+
   if ((flags  (SECTION_CODE | SECTION_WRITE)) == 0)
 /* readonly data */
 {
Index: gcc/gcc/configure.ac
===
--- gcc.orig/gcc/configure.ac
+++ gcc/gcc/configure.ac
@@ -3553,6 +3553,15 @@ foo: nop
  ;;
  esac
fi
+   # Test if the assembler supports the section flag 'e' for specifying
+   # an excluded section.
+   gcc_GAS_CHECK_FEATURE([.section with e], gcc_cv_as_section_has_e,
+ [2,22,51],,
+[.section foo1,e
+.byte 0,0,0,0])
+   AC_DEFINE_UNQUOTED(HAVE_GAS_SECTION_EXCLUDE,
+ [`if test $gcc_cv_as_section_has_e = yes; then echo 1; else echo 0; 
fi`],
+  [Define if your assembler supports specifying the section flag e.])
;;
 esac


Re: [patch windows]: Support SECTION_EXCLUDE for pe-coff targets

2011-09-27 Thread Kai Tietz
2011/9/27 Richard Henderson r...@redhat.com:
 On 09/27/2011 12:58 PM, Kai Tietz wrote:
 +#ifdef HAVE_GAS_SECTION_EXCLUDE
 +  if ((flags  SECTION_EXCLUDE) != 0)
 +    *f++ = 'e';
 +#endif

 If 'e' is not supported, I wonder if we should emit 'n'?

 Otherwise ok.


 r~

This sounds fair.  At least we take care that section doesn't get
loaded into memory.
I adjust patch, retest it and then apply.

Thanks,
Kai


Re: [patch] --enable-dynamic-string default for mingw-w64 v2

2011-10-01 Thread Kai Tietz
2011/10/1 Pedro Alves pe...@codesourcery.com:
 On Saturday 01 October 2011 12:15:42, JonY wrote:
 On 10/1/2011 18:33, Pedro Alves wrote:
  On Saturday 01 October 2011 07:03:35, JonY wrote:
  Hi,
 
  I followed Paolo's suggestion with the os_defines.h trick. I duplicated
  os/mingw32/ to os/mingw32-w64/ for this to work, since there aren't any
  built-in defines to tell the 2 apart unless you include some headers
  like _mingw.h.
 
  Are we really introducing a bunch of duplication between
  os/mingw32/ and os/mingw32-w64/ ?  I didn't see the part that adds the
  new dir and does all those copies in the patch; where is it?  Or have
  I missed something?  Can't we make configure add
  -D__IM_REALLY_W64_YOU_KNOW to CFLAGS instead?  Or come up with a way
  to point libstd++ to pick up a new mingw32/os_defines_w64.h file instead
  that does:
 
  #include os_defines.h
  // mingw-w64 should use fully-dynamic-string by default
  #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
  #define _GLIBCXX_FULLY_DYNAMIC_STRING 1
  #endif
 

 The new files are missing from svn diff because I used svn copy to copy
 the directories, svn diff didn't show them, should I use something else
 instead?

 So that'd be a patch with its own ChangeLog, as your patch applies on
 top of that already.

 IMHO, mingw.org and mingw-w64 may or may not diverge further in the
 future, so sprinkling defines to codes isn't very good in the long run.

 may or may not is key.  We don't know the future, but we know
 the present. We do know that code duplication is bad.  I can just
 as well say,

Well, this situation isn't ideal.  It might be that one day mingw.org
and mingw-w64 venture come more near in feature-set.  But this is for
sure more a long-term issue and not a short or medium-term thing.

 IMHO, mingw.org and mingw-w64 may or may not diverge further in the
 future (ideally they wouldn't), so adding code duplication when
 we only need one define isn't very good in the long run.

 But I'm not a maintainer, so I shall just go away.

Well, we diverge already more and more.  I plan to provide for
libstdc++ some new printf/scanf API features for wide and ascii
variants, which is present in mingw-w64 venture, but not in mingw.org
venture.  We have also other divergencies in other feature-set, which
lead already to an add-on header in gcc for specific mingw-w64
targets.

Kai


Re: [PATCH] [mingw] fix typo: s/_REENTRANCE/_REENTRANT/

2011-10-03 Thread Kai Tietz
2011/10/3 Ozkan Sezer seze...@gmail.com:
 PING?

 On Thu, Sep 22, 2011 at 2:28 PM, Ozkan Sezer seze...@gmail.com wrote:
 Hi:

 Unless I'm missing something, the mingw CPP_SPEC changes introduced in
 r171833 have a typo: -D_REENTRANCE should read -D_REENTRANT . Patchlet
 below.  Please review, and apply if it's OK.


 config/i386/mingw-w64.h (CPP_SPEC): Rename _REENTRANCE to _REENTRANT.
 config/i386/mingw32.h (CPP_SPEC): Likewise.

 Index: config/i386/mingw-w64.h
 ===
 --- config/i386/mingw-w64.h     (revision 171833)
 +++ config/i386/mingw-w64.h     (working copy)
 @@ -25,8 +25,8 @@
  #undef CPP_SPEC
  #define CPP_SPEC %{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT}  \
                 %{municode:-DUNICODE}  \
 -                %{ SPEC_PTHREAD1 :-D_REENTRANCE}  \
 -                %{ SPEC_PTHREAD2 :-U_REENTRANCE} 
 +                %{ SPEC_PTHREAD1 :-D_REENTRANT}  \
 +                %{ SPEC_PTHREAD2 :-U_REENTRANT} 

  #undef STARTFILE_SPEC
  #define STARTFILE_SPEC %{shared|mdll:dllcrt2%O%s} \
 Index: config/i386/mingw32.h
 ===
 --- config/i386/mingw32.h       (revision 177789)
 +++ config/i386/mingw32.h       (working copy)
 @@ -87,7 +87,7 @@

  #undef CPP_SPEC
  #define CPP_SPEC %{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT}  \
 -                %{ SPEC_PTHREAD1 :-D_REENTRANCE}  \
 +                %{ SPEC_PTHREAD1 :-D_REENTRANT}  \
                 %{ SPEC_PTHREAD2 : } 

  /* For Windows applications, include more libraries, but always include


 --
 O.S.


Patch is ok together with a ChangeLog.

Thanks,
Kai


[patch tree-optimization]: 1 of 2: Add normalization of bitwise-operations to tree-ssa-reassoc pass

2011-10-04 Thread Kai Tietz
Hello,

This patch (one of two) adds to tree-ssa-reassociation code for
expansion of packed
bitwise-binary operations - like (X | Y) == 0, etc.
Also it normalizes bitwise-not operations on bitwise-binary tree
chains - like ~(X | Y) - ~X  ~Y.

ChangeLog

2011-10-04  Kai Tietz  kti...@redhat.com

* tree-ssa-reassoc.c (gimple build_and_add_sum): Add forwader
and add support for unary expressions.
(remove_stmt_chain): New function for removing statement-chain
recursively without checking for visited state.
(make_new_tmp_statement): New helper function to generate
temporary register statement.
(expand_not_bitwise_binary): Helper for applying bitwise-not
on a tree-chain.
(expand_cmp_ior): Helper for expand packed bitwise-binary
combined statement.
(break_up_bitwise_combined_stmt): New function.
(break_up_subtract_bb): Rename to
(break_up_expr_bb): this.
(do_reassoc): Call break_up_expr_bb instead of break_up_subtract_bb.


ChangeLog

2011-10-04  Kai Tietz  kti...@redhat.com


* gcc.dg/tree-ssa/reassoc-30.c: New file.
* gcc.dg/tree-ssa/reassoc-31.c: New file.
* gcc.dg/tree-ssa/reassoc-26.c: New file.
* gcc.dg/tree-ssa/reassoc-27.c: New file.
* gcc.dg/tree-ssa/reassoc-28.c: New file.
* gcc.dg/tree-ssa/reassoc-29.c: New file.

Bootstrapped and regression tested for all languages (including Ada
and Obj-C++) on host x86_64-pc-linux-gnu.
Ok for apply?

Regards,
Kai

Index: gcc/gcc/tree-ssa-reassoc.c
===
--- gcc.orig/gcc/tree-ssa-reassoc.c
+++ gcc/gcc/tree-ssa-reassoc.c
@@ -44,6 +44,10 @@ along with GCC; see the file COPYING3.
 #include params.h
 #include diagnostic-core.h

+/* Forwarders.  */
+static gimple build_and_add_sum (tree, tree, tree, enum tree_code);
+static void remove_stmt_chain (tree);
+
 /*  This is a simple global reassociation pass.  It is, in part, based
 on the LLVM pass of the same name (They do some things more/less
 than we do, in different orders, etc).
@@ -51,7 +55,9 @@ along with GCC; see the file COPYING3.
 It consists of five steps:

 1. Breaking up subtract operations into addition + negate, where
-it would promote the reassociation of adds.
+it would promote the reassociation of adds.  Additionally breaking
+up combined expression made out of boolean-typed bitwise expressions
+for improving simplification.

 2. Left linearization of the expression trees, so that (A+B)+(C+D)
 becomes (((A+B)+C)+D), which is easier for us to rewrite later.
@@ -557,6 +563,412 @@ get_unary_op (tree name, enum tree_code
   return NULL_TREE;
 }

+/* Create a temporary register expression with type TYPE, tree code CODE, and
+   operands OP1 and OP2.  If REF_DEF is a valid gimple statement, we use its
+   location information for new generated temporary.
+   Function returns left-hand-side of new generated temporary register.  */
+
+static tree
+make_new_tmp_statement (tree type, enum tree_code code, tree op1, tree op2,
+   gimple ref_def)
+{
+  gimple sum;
+  tree tmpvar = create_tmp_reg (type, NULL);
+  add_referenced_var (tmpvar);
+  sum = build_and_add_sum (tmpvar, op1, op2, code);
+  if (ref_def)
+gimple_set_location (sum, gimple_location (ref_def));
+  return gimple_get_lhs (sum);
+}
+
+/* Perform on tree LHS with optional definition statement EXPR
+   the logic-not operation.  TYPE is of kind boolean.  */
+
+static tree
+expand_not_bitwise_binary (tree type, tree lhs, gimple expr)
+{
+  enum tree_code code = ERROR_MARK;
+  tree op1 = NULL, op2 = NULL;
+  gimple s1 = NULL, s2 = NULL;
+
+  if (TREE_CODE (lhs) == INTEGER_CST)
+return fold_build1 (BIT_NOT_EXPR, type, lhs);
+
+  if (expr  is_gimple_assign (expr))
+code = gimple_assign_rhs_code (expr);
+
+  /* If statement lhs isn't a single-use statement,
+ we don't want to modify it. So we can do only default-case
+ operation for it.  */
+  if (code != ERROR_MARK  !has_single_use (lhs))
+code = ERROR_MARK;
+
+  if (TREE_CODE_CLASS (code) == tcc_comparison
+  || code == BIT_XOR_EXPR
+  || code == BIT_AND_EXPR
+  || code == BIT_IOR_EXPR)
+{
+  op1 = gimple_assign_rhs1 (expr);
+  op2 = gimple_assign_rhs2 (expr);
+}
+  else if (code == BIT_NOT_EXPR)
+op1 = gimple_assign_rhs1 (expr);
+  else
+return make_new_tmp_statement (TREE_TYPE (lhs), BIT_NOT_EXPR, lhs,
+  NULL_TREE, expr);
+
+  /* ~(~X) - X.  */
+  if (code == BIT_NOT_EXPR)
+return op1;
+
+  /* Invert comparison if possible, otherwise fall through to
+ default case.  */
+  else if (TREE_CODE_CLASS (code) == tcc_comparison)
+{
+  enum tree_code ncode;
+  tree op1type = TREE_TYPE (op1);
+
+  ncode = invert_tree_comparison (code,
+ HONOR_NANS (TYPE_MODE (op1type)));
+  if (ncode

Re: [PATCH] [mingw] fix typo: s/_REENTRANCE/_REENTRANT/

2011-10-04 Thread Kai Tietz
2011/10/3 Ozkan Sezer seze...@gmail.com:
 On Mon, Oct 3, 2011 at 5:56 PM, Kai Tietz ktiet...@googlemail.com wrote:
 2011/10/3 Ozkan Sezer seze...@gmail.com:
 PING?

 On Thu, Sep 22, 2011 at 2:28 PM, Ozkan Sezer seze...@gmail.com wrote:
 Hi:

 Unless I'm missing something, the mingw CPP_SPEC changes introduced in
 r171833 have a typo: -D_REENTRANCE should read -D_REENTRANT . Patchlet
 below.  Please review, and apply if it's OK.


 config/i386/mingw-w64.h (CPP_SPEC): Rename _REENTRANCE to _REENTRANT.
 config/i386/mingw32.h (CPP_SPEC): Likewise.

 Index: config/i386/mingw-w64.h
 ===
 --- config/i386/mingw-w64.h     (revision 171833)
 +++ config/i386/mingw-w64.h     (working copy)
 @@ -25,8 +25,8 @@
  #undef CPP_SPEC
  #define CPP_SPEC %{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT}  \
                 %{municode:-DUNICODE}  \
 -                %{ SPEC_PTHREAD1 :-D_REENTRANCE}  \
 -                %{ SPEC_PTHREAD2 :-U_REENTRANCE} 
 +                %{ SPEC_PTHREAD1 :-D_REENTRANT}  \
 +                %{ SPEC_PTHREAD2 :-U_REENTRANT} 

  #undef STARTFILE_SPEC
  #define STARTFILE_SPEC %{shared|mdll:dllcrt2%O%s} \
 Index: config/i386/mingw32.h
 ===
 --- config/i386/mingw32.h       (revision 177789)
 +++ config/i386/mingw32.h       (working copy)
 @@ -87,7 +87,7 @@

  #undef CPP_SPEC
  #define CPP_SPEC %{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT}  \
 -                %{ SPEC_PTHREAD1 :-D_REENTRANCE}  \
 +                %{ SPEC_PTHREAD1 :-D_REENTRANT}  \
                 %{ SPEC_PTHREAD2 : } 

  /* For Windows applications, include more libraries, but always include


 --
 O.S.


 Patch is ok together with a ChangeLog.

 Thanks,
 Kai


 Here it is again with a changelog entry (Thought that I included one
 the first time..)  Thanks.

        * config/i386/mingw-w64.h (CPP_SPEC): Rename _REENTRANCE to _REENTRANT.
        * config/i386/mingw32.h (CPP_SPEC): Likewise.

 Index: config/i386/mingw-w64.h
 ===
 --- config/i386/mingw-w64.h     (revision 171833)
 +++ config/i386/mingw-w64.h     (working copy)
 @@ -25,8 +25,8 @@
  #undef CPP_SPEC
  #define CPP_SPEC %{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT}  \
                 %{municode:-DUNICODE}  \
 -                %{ SPEC_PTHREAD1 :-D_REENTRANCE}  \
 -                %{ SPEC_PTHREAD2 :-U_REENTRANCE} 
 +                %{ SPEC_PTHREAD1 :-D_REENTRANT}  \
 +                %{ SPEC_PTHREAD2 :-U_REENTRANT} 

  #undef STARTFILE_SPEC
  #define STARTFILE_SPEC %{shared|mdll:dllcrt2%O%s} \
 Index: config/i386/mingw32.h
 ===
 --- config/i386/mingw32.h       (revision 177789)
 +++ config/i386/mingw32.h       (working copy)
 @@ -87,7 +87,7 @@

  #undef CPP_SPEC
  #define CPP_SPEC %{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT}  \
 -                %{ SPEC_PTHREAD1 :-D_REENTRANCE}  \
 +                %{ SPEC_PTHREAD1 :-D_REENTRANT}  \
                 %{ SPEC_PTHREAD2 : } 

  /* For Windows applications, include more libraries, but always include

 --
 O.S.

Applied for you at revision 179511.

Regards,
Kai


Re: [patch tree-optimization]: Improve handling of conditional-branches on targets with high branch costs

2011-10-06 Thread Kai Tietz
Hello,

Sorry attached non-updated change.  Here with proper attached patch.
This patch improves in fold_truth_andor the generation of branch-conditions for 
targets having LOGICAL_OP_NON_SHORT_CIRCUIT set.  If right-hand side operation 
of a TRUTH_(OR|AND)IF_EXPR is simple operand, has no side-effects, and doesn't 
trap, then try to convert expression to a TRUTH_(AND|OR)_EXPR, if left-hand 
operand is a simple operand, and has no side-effects.

ChangeLog

2011-10-06  Kai Tietz  kti...@redhat.com

* fold-const.c (fold_truth_andor): Convert TRUTH_(AND|OR)IF_EXPR
to TRUTH_OR_EXPR, if suitable.

Bootstrapped and tested for all languages (including Ada and Obj-C++) on host 
x86_64-unknown-linux-gnu.  Ok for apply?

Regards,
Kai


ndex: fold-const.c
===
--- fold-const.c(revision 179592)
+++ fold-const.c(working copy)
@@ -8387,6 +8387,33 @@
   if ((tem = fold_truthop (loc, code, type, arg0, arg1)) != 0)
 return tem;

+  if ((code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
+   !TREE_SIDE_EFFECTS (arg1)
+   simple_operand_p (arg1)
+   LOGICAL_OP_NON_SHORT_CIRCUIT
+   !FLOAT_TYPE_P (TREE_TYPE (arg1))
+   ((TREE_CODE_CLASS (TREE_CODE (arg1)) != tcc_comparison
+   TREE_CODE (arg1) != TRUTH_NOT_EXPR)
+ || !FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg1, 0)
+{
+  if (TREE_CODE (arg0) == code
+   !TREE_SIDE_EFFECTS (TREE_OPERAND (arg0, 1))
+   simple_operand_p (TREE_OPERAND (arg0, 1)))
+   {
+ tem = build2_loc (loc,
+   (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
+ : TRUTH_OR_EXPR),
+   type, TREE_OPERAND (arg0, 1), arg1);
+   return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem);
+  }
+  if (!TREE_SIDE_EFFECTS (arg0)
+   simple_operand_p (arg0))
+   return build2_loc (loc,
+  (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
+: TRUTH_OR_EXPR),
+  type, arg0, arg1);
+}
+
   return NULL_TREE;
 }



Re: [patch tree-optimization]: Improve handling of conditional-branches on targets with high branch costs

2011-10-06 Thread Kai Tietz
2011/10/6 Richard Guenther richard.guent...@gmail.com:
 On Thu, Oct 6, 2011 at 11:28 AM, Kai Tietz kti...@redhat.com wrote:
 Hello,

 Sorry attached non-updated change.  Here with proper attached patch.
 This patch improves in fold_truth_andor the generation of branch-conditions 
 for targets having LOGICAL_OP_NON_SHORT_CIRCUIT set.  If right-hand side 
 operation of a TRUTH_(OR|AND)IF_EXPR is simple operand, has no side-effects, 
 and doesn't trap, then try to convert expression to a TRUTH_(AND|OR)_EXPR, 
 if left-hand operand is a simple operand, and has no side-effects.

 ChangeLog

 2011-10-06  Kai Tietz  kti...@redhat.com

        * fold-const.c (fold_truth_andor): Convert TRUTH_(AND|OR)IF_EXPR
        to TRUTH_OR_EXPR, if suitable.

 Bootstrapped and tested for all languages (including Ada and Obj-C++) on 
 host x86_64-unknown-linux-gnu.  Ok for apply?

 Regards,
 Kai


 ndex: fold-const.c
 ===
 --- fold-const.c        (revision 179592)
 +++ fold-const.c        (working copy)
 @@ -8387,6 +8387,33 @@
   if ((tem = fold_truthop (loc, code, type, arg0, arg1)) != 0)
     return tem;

 +  if ((code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
 +       !TREE_SIDE_EFFECTS (arg1)
 +       simple_operand_p (arg1)
 +       LOGICAL_OP_NON_SHORT_CIRCUIT

 Why only for LOGICAL_OP_NON_SHORT_CIRCUIT?  It doesn't make
 a difference for !LOGICAL_OP_NON_SHORT_CIRCUIT targets, but ...
Well, I used this check only for not doing this transformation for
targets, which have low-cost branches.  This is the same thing as in
fold_truthop.  It does this transformation only if
LOGICAL_OP_NON_SHORT_CIRCUIT is true.
 +       !FLOAT_TYPE_P (TREE_TYPE (arg1))

 ?  I hope we don't have || float.
This can happen.  Operands of TRUTH_AND|OR(IF)_EXPR aren't necessarily
of integral type.  After expansion in gimplifier, we have for sure
comparisons, but not in c-tree.

 +       ((TREE_CODE_CLASS (TREE_CODE (arg1)) != tcc_comparison
 +           TREE_CODE (arg1) != TRUTH_NOT_EXPR)
 +         || !FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg1, 0)

 ?  simple_operand_p would have rejected both ! and comparisons.
This check is the same as in fold_truthop.  I used this check.  The
point here is that floats might trap.

 I miss a test for side-effects on arg0 (and probably simple_operand_p there,
 as well).
See inner of if condition for those checks.  I moved those checks for
arg1 out of the inner conditions to avoid double-checking.

 +    {
 +      if (TREE_CODE (arg0) == code
 +           !TREE_SIDE_EFFECTS (TREE_OPERAND (arg0, 1))
 +           simple_operand_p (TREE_OPERAND (arg0, 1)))

 Err ... so why do you recurse here (and associate)?  Even with different
 predicates than above ...

See, here is the missing check. Point is that even if arg0 has
side-effects and is a (AND|OR)IF expression, we might be able to
associate with right-hand argument of arg0, if for it no side-effects
are existing.  Otherwise we wouldn't catch this case.
We have here in maximum a recursion level of one.

 And similar transforms seem to happen in fold_truthop - did you
 investigate why it didn't trigger there.

This is pretty simple.  The point is that only for comparisons this
transformation is done.  But in c-tree we don't have here necessarily
for TRUTH_(AND|OR)[IF]_EXPR comparison arguments, not necessarily
integral ones (see above).

 And I'm missing a testcase.

Ok, I'll add one.  Effect can be seen best after gimplification.

 Richard.

 +       {
 +         tem = build2_loc (loc,
 +                           (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
 +                                                     : TRUTH_OR_EXPR),
 +                           type, TREE_OPERAND (arg0, 1), arg1);
 +       return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), 
 tem);
 +      }
 +      if (!TREE_SIDE_EFFECTS (arg0)
 +           simple_operand_p (arg0))
 +       return build2_loc (loc,
 +                          (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
 +                                                    : TRUTH_OR_EXPR),
 +                          type, arg0, arg1);
 +    }
 +
   return NULL_TREE;
  }

Regards.
Kai


Re: [patch tree-optimization]: Improve handling of conditional-branches on targets with high branch costs

2011-10-06 Thread Kai Tietz
Hi,

I modified the patch so, that it always just converts two leafs of a 
TRUTH(AND|OR)IF chain into a TRUTH_(AND|OR) expression, if branch costs are 
high and leafs are simple without side-effects.

Additionally I added some testcases for it.

2011-10-06  Kai Tietz  kti...@redhat.com

* fold-const.c (fold_truth_andor): Convert TRUTH_(AND|OR)IF_EXPR
to TRUTH_OR_EXPR, if suitable.

2011-10-06  Kai Tietz  kti...@redhat.com

* gcc.dg/tree-ssa/ssa-ifbranch-1.c: New test.
* gcc.dg/tree-ssa/ssa-ifbranch-2.c: New test.
* gcc.dg/tree-ssa/ssa-ifbranch-3.c: New test.
* gcc.dg/tree-ssa/ssa-ifbranch-4.c: New test.

Bootstrapped and tested for all languages (including Ada and Obj-C++) on host 
x86_64-unknown-linux-gnu.  Ok for apply?

Regards,
Kai

Index: gcc-head/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifbranch-1.c
===
--- /dev/null
+++ gcc-head/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifbranch-1.c
@@ -0,0 +1,18 @@
+/* Skip on MIPS, S/390, and AVR due LOGICAL_OP_NON_SHORT_CIRCUIT, and
+   lower values in BRANCH_COST.  */
+/* { dg-do compile { target { ! mips*-*-* s390*-*-*  avr-*-* mn10300-*-* } } 
} */
+/* { dg-options -O2 -fdump-tree-gimple } */
+/* { dg-options -O2 -fdump-tree-gimple -march=i586 { target { i?86-*-*  
ilp32 } } } */
+
+extern int doo1 (void);
+extern int doo2 (void);
+
+int bar (int a, int b, int c)
+{
+  if (a  b  c)
+return doo1 ();
+  return doo2 ();
+}
+
+/* { dg-final { scan-tree-dump-times if  2 gimple } } */
+/* { dg-final { cleanup-tree-dump gimple } } */
Index: gcc-head/gcc/fold-const.c
===
--- gcc-head.orig/gcc/fold-const.c
+++ gcc-head/gcc/fold-const.c
@@ -8387,6 +8387,45 @@ fold_truth_andor (location_t loc, enum t
   if ((tem = fold_truthop (loc, code, type, arg0, arg1)) != 0)
 return tem;
 
+  if ((code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
+   !TREE_SIDE_EFFECTS (arg1)
+   LOGICAL_OP_NON_SHORT_CIRCUIT
+  /* floats might trap.  */
+   !FLOAT_TYPE_P (TREE_TYPE (arg1))
+   ((TREE_CODE_CLASS (TREE_CODE (arg1)) != tcc_comparison
+TREE_CODE (arg1) != TRUTH_NOT_EXPR
+simple_operand_p (arg1))
+  || ((TREE_CODE_CLASS (TREE_CODE (arg1)) == tcc_comparison
+   || TREE_CODE (arg1) == TRUTH_NOT_EXPR)
+ /* Float comparison might trap.  */
+   !FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg1, 0)))
+   simple_operand_p (TREE_OPERAND (arg1, 0)
+{
+  /* We want to combine truth-comparison for
+((W TRUTH-ANDOR X) TRUTH-ANDORIF Y) TRUTH-ANDORIF Z,
+if Y and Z are simple operands and have no side-effect to
+((W TRUTH-ANDOR X) TRUTH-IF (Y TRUTH-ANDOR Z).  */
+  if (TREE_CODE (arg0) == code
+   !TREE_SIDE_EFFECTS (TREE_OPERAND (arg0, 1))
+   simple_operand_p (TREE_OPERAND (arg0, 1)))
+   {
+ tem = build2_loc (loc,
+   (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
+ : TRUTH_OR_EXPR),
+   type, TREE_OPERAND (arg0, 1), arg1);
+ return build2_loc (loc, code, type, TREE_OPERAND (arg0, 0),
+tem);
+   }
+  /* Convert X TRUTH-ANDORIF Y to X TRUTH-ANDOR Y, if X and Y
+are simple operands and have no side-effects.  */
+  if (simple_operand_p (arg0)
+   !TREE_SIDE_EFFECTS (arg0))
+   return build2_loc (loc,
+  (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
+: TRUTH_OR_EXPR),
+  type, arg0, arg1);
+}
+
   return NULL_TREE;
 }
 
Index: gcc-head/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifbranch-2.c
===
--- /dev/null
+++ gcc-head/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifbranch-2.c
@@ -0,0 +1,18 @@
+/* Skip on MIPS, S/390, and AVR due LOGICAL_OP_NON_SHORT_CIRCUIT, and
+   lower values in BRANCH_COST.  */
+/* { dg-do compile { target { ! mips*-*-* s390*-*-*  avr-*-* mn10300-*-* } } 
} */
+/* { dg-options -O2 -fdump-tree-gimple } */
+/* { dg-options -O2 -fdump-tree-gimple -march=i586 { target { i?86-*-*  
ilp32 } } } */
+
+extern int doo1 (void);
+extern int doo2 (void);
+
+int bar (int a, int b, int c, int d)
+{
+  if (a  b  c  d)
+return doo1 ();
+  return doo2 ();
+}
+
+/* { dg-final { scan-tree-dump-times if  2 gimple } } */
+/* { dg-final { cleanup-tree-dump gimple } } */
Index: gcc-head/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifbranch-3.c
===
--- /dev/null
+++ gcc-head/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifbranch-3.c
@@ -0,0 +1,18 @@
+/* Skip on MIPS, S/390, and AVR due LOGICAL_OP_NON_SHORT_CIRCUIT, and
+   lower values in BRANCH_COST.  */
+/* { dg-do compile { target { ! mips*-*-* s390*-*-*  avr-*-* mn10300

Re: [patch tree-optimization]: Improve handling of conditional-branches on targets with high branch costs

2011-10-06 Thread Kai Tietz
2011/10/6 Michael Matz m...@suse.de:
 Hi,

 On Thu, 6 Oct 2011, Richard Guenther wrote:

  +       ((TREE_CODE_CLASS (TREE_CODE (arg1)) != tcc_comparison
  +           TREE_CODE (arg1) != TRUTH_NOT_EXPR)
  +         || !FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg1, 0)

 ?  simple_operand_p would have rejected both ! and comparisons.

 I miss a test for side-effects on arg0 (and probably simple_operand_p there,
 as well).

 He has it in the if() body.  But why?  The point of ANDIF/ORIF is to not
 evaluate the second argument for side-effects when the first argument is
 false/true already, and further to establish an order between both
 evaluations.  The sideeffect on the first arg is always evaluated.
 AND/OR always evaluate both arguments (in unspecified order), but as he
 checks the second one for being free of side effects already that alone is
 already equivalent to ANDIF/ORIF.  No need to check something on the first
 argument.


 Ciao,
 Michael.


That's not the hole story.  The difference between
TRUTH_(AND|OR)IF_EXPR and TRUTH_(AND|OR)_EXPR are, that for
TRUTH_(AND|OR)IF_EXPR gimplifier creates a COND expression, but for
TRUTH_(AND|OR)_EXPR it doesn't.

Regards,
Kai


Re: [patch tree-optimization]: Improve handling of conditional-branches on targets with high branch costs

2011-10-06 Thread Kai Tietz
2011/10/6 Michael Matz m...@suse.de:
 Hi,

 On Thu, 6 Oct 2011, Kai Tietz wrote:

 That's not the hole story.  The difference between TRUTH_(AND|OR)IF_EXPR
 and TRUTH_(AND|OR)_EXPR are, that for TRUTH_(AND|OR)IF_EXPR gimplifier
 creates a COND expression, but for TRUTH_(AND|OR)_EXPR it doesn't.

 Yes, of course.  That is what implements the short-circuit semantics.  But
 as Richard already mentioned I also don't understand why you do the
 reassociation at that point.  Why not simply rewrite ANDIF - AND (when
 possible, i.e. no sideeffects on arg1, and desirable, i.e. when
 LOGICAL_OP_NON_SHORT_CIRCUIT, and simple_operand(arg1)) and let other
 folders do reassociation?  I ask because your comments states to
 transform:

  ((W AND X) ANDIF Y) ANDIF Z
 into
  (W AND X) ANDIF (Y AND Z)

 (under condition that Y and Z are simple operands).

 In fact you don't check the form of arg0,0, i.e. the W AND X here.
 Independend of that it doesn't make sense, because if Y and Z are easy
 (simple and no side-effects), then Y AND Z is too, and therefore you
 should transform this (if at all) into:

  (W AND X) AND (Y AND Z)

 at which point this association doesn't make sense anymore, as

Sorry, exactly this doesn't happen, due an ANDIF isn't simple, and
therefore it isn't transformed into and AND.


  ((W AND X) AND Y) AND Z

 is just as fine.  So, the reassociation looks fishy at best, better get
 rid of it?  (which of the testcases breaks without it?)

None.  I had this implemented first.  But Richard was concerned about
making non-IF conditions too long.I understand that point that it
might not that good to always modify unconditionally to AND/OR chain.
For example

if (a1  a2  a3    a100) return 1;

would be packed by this patch into 50 branches.   If we would modify
all of them into AND, then we would calculate for all 100 values the
result, even if the first a1 is zero.  This doesn't improve speed
pretty well.

But you are right, that from the point of reassociation optimization
it could be in some cases more profitable to have packed all elements
into on AND-chain.

Regards,
Kai


Re: [patch tree-optimization]: Improve handling of conditional-branches on targets with high branch costs

2011-10-06 Thread Kai Tietz
2011/10/6 Michael Matz m...@suse.de:
 Hi,

 On Thu, 6 Oct 2011, Kai Tietz wrote:

  at which point this association doesn't make sense anymore, as

 Sorry, exactly this doesn't happen, due an ANDIF isn't simple, and
 therefore it isn't transformed into and AND.

 Right ...

   ((W AND X) AND Y) AND Z
 
  is just as fine.  So, the reassociation looks fishy at best, better get
  rid of it?  (which of the testcases breaks without it?)

 None.  I had this implemented first.  But Richard was concerned about
 making non-IF conditions too long.    I understand that point that it
 might not that good to always modify unconditionally to AND/OR chain.

 ... and I see that (that's why the transformation should be desirable for
 some definition of desirable, which probably includes and RHS not too
 long chain).  As it stands right now your transformation seems to be a
 fairly ad-hoc try at avoiding this problem.  That's why I wonder why to do
 the reassoc at all?  Which testcases break _without_ the reassociation,
 i.e. with only rewriting ANDIF - AND at the outermost level?

I don't do here reassociation in inner.  See that patch calls
build2_loc, and not fold_build2_loc anymore.  So it doesn't retries to
associate in inner anymore (which might be something of interest for
the issue Jakub mentioned).

There is no test actual failing AFAICS.  I just noticed
size-differences by this.  Nevertheless it might be better to enhance
reassociation pass to break-up (and repropagate) GIMPLE_CONDs with
non-side-effect, as Jakub suggested.

The other chance might be here to allow deeper chains then two
elements within one AND/OR element, but this would be architecture
dependent.  For x86 -as example- used instruction cycles for a common
for branching would suggest that it might be profitable to have here 3
or 4 leafs within one AND|OR chain.  But for sure on other
architectures the amount of leafs varies.

Regards,
Kai


[patch tree-optimization]: 2 of 6 Improve reassoc for bitwise operations

2011-10-07 Thread Kai Tietz
Hello,

This patch adds the repropagation of expanded bitwise-not expressions.

ChangeLog

2011-10-07  Kai Tietz  kti...@redhat.com

* tree-ssa-reassoc.c (walk_bitwise_stmt_elems): Helper
to collect different kinds of operands of a bitwise-binary
expression chain.
(rebuild_vector_tree): Helper function to create out of
a vector list a bitwise-binary kind statement-chain.
(operate_bitwise_xor_stmt): Perform repropagation for a XOR
statement chain.
(operate_bitwise_stmt): Handler to repropagate a bitwise
statement-chain.
(repropagate_bitwise): Handler to repropage bitwise-binaries.
(execute_reassoc): Make use of repropagate_bitwise.


2011-10-07  Kai Tietz  kti...@redhat.com

* gcc.dg/tree-ssa/reassoc-not-1.c: New file.

Bootstrapped and regression-tested for all languages plus Ada and
Obj-C++ on x86_64-pc-linux-gnu.
Ok for apply?

Regards,
Kai

Index: gcc/gcc/tree-ssa-reassoc.c
===
--- gcc.orig/gcc/tree-ssa-reassoc.c
+++ gcc/gcc/tree-ssa-reassoc.c
@@ -3110,6 +3110,366 @@ linearize_expr_tree (VEC(operand_entry_t
   add_to_ops_vec (ops, binrhs);
 }

+/* Split up a binary tree-chain of code CODE - starting at STMT - into three
+   different kinds:
+   - vector VCST stores constant values.
+   - vector VNOT stores bitwise-not expressions.
+   - vector VEXRR stores the remaining rest. */
+
+static void
+walk_bitwise_stmt_elems (gimple stmt, enum tree_code code,
+VEC(tree, heap) **vcst,
+VEC(tree, heap) **vnot,
+VEC(tree, heap) **vexpr)
+{
+  gimple s;
+  tree l;
+
+  l = gimple_assign_rhs1 (stmt);
+  if (TREE_CODE (l) == INTEGER_CST)
+VEC_safe_push (tree, heap, *vcst, l);
+  else if (TREE_CODE (l) != SSA_NAME
+  || (s = SSA_NAME_DEF_STMT (l)) == NULL
+  || !is_gimple_assign (s)
+  || !has_single_use (l))
+VEC_safe_push (tree, heap, *vexpr, l);
+  else if (gimple_assign_rhs_code (s) == code)
+walk_bitwise_stmt_elems (s, code, vcst, vnot, vexpr);
+  else if (gimple_assign_rhs_code (s) == BIT_NOT_EXPR)
+VEC_safe_push (tree, heap, *vnot, l);
+  else
+VEC_safe_push (tree, heap, *vexpr, l);
+
+  l = gimple_assign_rhs2 (stmt);
+
+  if (TREE_CODE (l) == INTEGER_CST)
+{
+  VEC_safe_push (tree, heap, *vcst, l);
+  return;
+}
+  if (TREE_CODE (l) != SSA_NAME
+  || (s = SSA_NAME_DEF_STMT (l)) == NULL
+  || !is_gimple_assign (s)
+  || !has_single_use (l))
+VEC_safe_push (tree, heap, *vexpr, l);
+  else if (gimple_assign_rhs_code (s) == code)
+walk_bitwise_stmt_elems (s, code, vcst, vnot, vexpr);
+  else if (gimple_assign_rhs_code (s) == BIT_NOT_EXPR)
+VEC_safe_push (tree, heap, *vnot, l);
+  else
+VEC_safe_push (tree, heap, *vexpr, l);
+}
+
+/* Helper function to rebuild a binary tree of CODE elements
+   from vector VEC.
+   If LASTP is NULL, then all elements are combined and the result is
+   returned.  Otherwise the last element of vector VEC is stored in LASTP
+   and all - but the last - elements are merged and returned.
+   Note: for vector with just one element, this element is returned
+   and LASTP is set to NULL, if provided.
+   If INNER_LEFT has value TRUE, then the RHS1 operand of VEC elements
+   are used for combining.  Otherwise the VEC elements itself are used.  */
+
+static tree
+rebuild_vector_tree (VEC(tree, heap) *vec,
+enum tree_code code, tree *lastp, bool inner_left)
+{
+  gimple s;
+  unsigned int i = 0;
+  tree r = NULL_TREE, x, r2 = NULL_TREE;
+
+  FOR_EACH_VEC_ELT (tree, vec, i, x)
+{
+  s = SSA_NAME_DEF_STMT (x);
+
+  if (inner_left)
+   x = gimple_assign_rhs1 (s);
+  if (!r)
+r = x;
+  else if (!r2)
+r2 = x;
+  else
+{
+ r = make_new_tmp_statement (TREE_TYPE (r), code, r, r2, s);
+ r2 = x;
+   }
+}
+  if (lastp)
+*lastp = r2;
+  else if (r  r2)
+{
+  s = SSA_NAME_DEF_STMT (r);
+  r = make_new_tmp_statement (TREE_TYPE (r), code, r, r2, s);
+}
+  return r;
+}
+
+/* Sink not-expression out of xor-expression-sequences.  This sequence
+   is made out of VNOT, VEXPR, and TCST.
+   It returns TRUE, if tree-chain PGSI - starting at STMT - was modified,
+   otherwise FALSE.  */
+
+static bool
+operate_bitwise_xor_stmt (gimple_stmt_iterator *pgsi, gimple stmt, tree tcst,
+ VEC(tree, heap) *vnot,
+ VEC(tree, heap) *vexpr)
+{
+  unsigned int i = VEC_length (tree, vnot);
+  tree l = NULL_TREE, r = NULL_TREE;
+  bool inv = false;
+
+  /* If the amount of not-expressions is odd, then we have two cases:
+ a) we have a constant, so we can sink one not into integeral constant
+as ~X ^ CST - X ^ CST' with CST' = ~CST.
+ b) we need to add to the hole statment a bitwise-not expression.  */
+  if ((i  1) != 0

[patch tree-optimization]: 1 of 6 Improve reassoc for bitwise operations

2011-10-07 Thread Kai Tietz
Hello,

This patch adds to the break-up pass the facility to sink bitwise-not operations
into bitwise-binary expressions.  Additionally it handles special
cases for ~(~X),
and ~(X cmp Y).

ChangeLog

2011-10-07  Kai Tietz  kti...@redhat.com

* tree-ssa-reassoc.c (remove_stmt_chain): Helper function
to remove gimple-assignment tree with all arms.
(make_new_tmp_statement): Helper function to create temporary
register expression.
(expand_not_bitwise_binary): Perform bitwise-not operation on
gimple-assignment tree.
(break_up_bitwise_combined_stmt): Break-up handler for bitwise-
operations.
(break_up_expr_bb): Adjust to call break_up_bitwise_combined_stmt.

2011-10-07  Kai Tietz  kti...@redhat.com

* gcc.dg/tree-ssa/reassoc-not-1.c: New file.
* gcc.dg/tree-ssa/reassoc-not-2.c: New file.
* gcc.dg/tree-ssa/reassoc-not-3.c: New file.

Bootstrapped and regression-tested for all languages plus Ada and
Obj-C++ on x86_64-pc-linux-gnu.
Ok for apply?

Regards,
Kai

Index: gcc/gcc/tree-ssa-reassoc.c
===
--- gcc.orig/gcc/tree-ssa-reassoc.c
+++ gcc/gcc/tree-ssa-reassoc.c
@@ -46,6 +46,7 @@ along with GCC; see the file COPYING3.

 /* Forwarders.  */
 static gimple build_and_add_sum (tree, tree, tree, enum tree_code);
+static void remove_stmt_chain (tree);

 /*  This is a simple global reassociation pass.  It is, in part, based
 on the LLVM pass of the same name (They do some things more/less
@@ -53,8 +54,11 @@ static gimple build_and_add_sum (tree, t

 It consists of five steps:

-1. Breaking up subtract operations into addition + negate, where
+1. Breaking up expressions
+1.1. Breaking up subtract operations into addition + negate, where
 it would promote the reassociation of adds.
+1.2. Breaking up to normalized form for bitwise-not operations
+on bitwise-binary and for bitwise-not operation on compares.

 2. Left linearization of the expression trees, so that (A+B)+(C+D)
 becomes (((A+B)+C)+D), which is easier for us to rewrite later.
@@ -560,6 +564,265 @@ get_unary_op (tree name, enum tree_code
   return NULL_TREE;
 }

+/* Create a temporary register expression with type TYPE, tree code CODE, and
+   operands OP1 and OP2.  If REF_DEF is a valid gimple statement, we use its
+   location information for new generated temporary.
+   Function returns left-hand-side of new generated temporary register.  */
+
+static tree
+make_new_tmp_statement (tree type, enum tree_code code, tree op1, tree op2,
+   gimple ref_def)
+{
+  gimple sum;
+  tree tmpvar = create_tmp_reg (type, NULL);
+  add_referenced_var (tmpvar);
+  sum = build_and_add_sum (tmpvar, op1, op2, code);
+  if (ref_def)
+gimple_set_location (sum, gimple_location (ref_def));
+  return gimple_get_lhs (sum);
+}
+
+/* Perform on tree LHS with optional definition statement EXPR
+   the logic-not operation.  TYPE is of kind boolean.  */
+
+static tree
+expand_not_bitwise_binary (tree type, tree lhs, gimple expr)
+{
+  enum tree_code code = ERROR_MARK;
+  tree op1 = NULL, op2 = NULL;
+  gimple s1 = NULL, s2 = NULL;
+
+  if (TREE_CODE (lhs) == INTEGER_CST)
+return fold_build1 (BIT_NOT_EXPR, type, lhs);
+
+  if (expr  is_gimple_assign (expr))
+code = gimple_assign_rhs_code (expr);
+
+  /* If statement lhs isn't a single-use statement,
+ we don't want to modify it. So we can do only default-case
+ operation for it.  */
+  if (code != ERROR_MARK  !has_single_use (lhs))
+code = ERROR_MARK;
+
+  if (TREE_CODE_CLASS (code) == tcc_comparison
+  || code == BIT_XOR_EXPR
+  || code == BIT_AND_EXPR
+  || code == BIT_IOR_EXPR)
+{
+  op1 = gimple_assign_rhs1 (expr);
+  op2 = gimple_assign_rhs2 (expr);
+}
+  /* ~(~X) - X.  */
+  else if (code == BIT_NOT_EXPR)
+return gimple_assign_rhs1 (expr);
+  else
+return make_new_tmp_statement (TREE_TYPE (lhs), BIT_NOT_EXPR, lhs,
+  NULL_TREE, expr);
+
+  /* ~(X cmp Y) - X cmp' Y, with cmp'=inverted comparison code, if allowed.
+ Otherwise fall through to default case.  */
+  if (TREE_CODE_CLASS (code) == tcc_comparison)
+{
+  enum tree_code ncode;
+  tree op1type = TREE_TYPE (op1);
+
+  ncode = invert_tree_comparison (code,
+ HONOR_NANS (TYPE_MODE (op1type)));
+  if (ncode != ERROR_MARK)
+   return make_new_tmp_statement (type, ncode, op1, op2, expr);
+}
+  /* Handle transformation for ~(A  B) - ~A | ~B or ~(A | B) - ~A  ~B.  */
+  else if (code == BIT_AND_EXPR || code == BIT_IOR_EXPR)
+{
+  /* See if left-hand operand is a gimple-assign, and has single-use. */
+  if (TREE_CODE (op1) != SSA_NAME
+  || !(s1 = SSA_NAME_DEF_STMT (op1))
+  || !is_gimple_assign (s1)
+  || !has_single_use (op1))
+   s1 = NULL;
+  /* See if right-hand

[patch tree-optimization]: 3 of 6 Improve reassoc for bitwise operations

2011-10-07 Thread Kai Tietz
Hello,

This patch adds to the break-up pass the facility to expand (X | Y) ==/!= 0
expression.  This enables in later reassociation pass better results.

ChangeLog

2011-10-07  Kai Tietz  kti...@redhat.com

* tree-ssa-reassoc.c (expand_cmp_ior): Helper for expanding
(X | Y) ==/!= 0 statments.
(break_up_bitwise_combined_stmt): Make use of expand_cmp_ior.

2011-10-07  Kai Tietz  kti...@redhat.com

* gcc.dg/tree-ssa/reassoc-cmpior-1.c: New file.
* gcc.dg/tree-ssa/reassoc-cmpior-2.c: New file.
* gcc.dg/tree-ssa/reassoc-cmpior-3.c: New file.

Bootstrapped and regression-tested for all languages plus Ada and
Obj-C++ on x86_64-pc-linux-gnu.
Ok for apply?

Regards,
Kai

Index: gcc/gcc/tree-ssa-reassoc.c
===
--- gcc.orig/gcc/tree-ssa-reassoc.c
+++ gcc/gcc/tree-ssa-reassoc.c
@@ -59,6 +59,8 @@ static void remove_stmt_chain (tree);
 it would promote the reassociation of adds.
 1.2. Breaking up to normalized form for bitwise-not operations
 on bitwise-binary and for bitwise-not operation on compares.
+1.3  Breaking up combined expression made out of boolean-typed bitwise
+expressions for improving simplification.

 2. Left linearization of the expression trees, so that (A+B)+(C+D)
 becomes (((A+B)+C)+D), which is easier for us to rewrite later.
@@ -712,8 +714,89 @@ expand_not_bitwise_binary (tree type, tr
 NULL_TREE, expr);
 }

+/* Routine to expand (X | Y) ==/!= 0 and doing
+   simplification on (X cmp Y) ==/!= 0.
+- (X | Y) == 0 to (X == 0)  (Y == 0)
+- (X | Y) != 0 to (X != 0) | (Y != 0).
+- (X cmp Y) == 0 to (X cmp' Y) with cmp'=invert of cmp.
+- (X cmp Y) != 0 to (X cmp Y).
+
+   The argument CODE can be either NE_EXPR, or EQ_EXPR.  It indicates
+   what kind of expansion is performed.  */
+
+static tree
+expand_cmp_ior (tree op, tree type, enum tree_code code)
+{
+  tree op1, op2;
+  gimple s = NULL;
+  enum tree_code hcode;
+
+  /* Handle integral constant value case.  */
+  if (TREE_CODE (op) == INTEGER_CST)
+{
+  if (code == EQ_EXPR)
+return fold_convert (type, (integer_zerop (op) ? integer_one_node
+   : integer_zero_node));
+  return fold_convert (type, (!integer_zerop (op) ? integer_one_node
+ : integer_zero_node));
+}
+
+  /* If operand OP isn't a gimple-assign, or has non-single use,
+ then simply creat a comparison != 0 for it.  */
+  if (TREE_CODE (op) != SSA_NAME
+  || !(s = SSA_NAME_DEF_STMT (op))
+  || !is_gimple_assign (s)
+  || !has_single_use (op))
+return make_new_tmp_statement (type, code, op,
+  build_zero_cst (TREE_TYPE (op)), s);
+
+  hcode = gimple_assign_rhs_code (s);
+
+  /* Operand code of OP isn't of comparison kind, and not
+ a bitwise-not, then creat a comparison != 0 for it.  */
+  if (TREE_CODE_CLASS (hcode) != tcc_comparison
+   hcode != BIT_IOR_EXPR)
+return make_new_tmp_statement (type, code, op,
+  build_zero_cst (TREE_TYPE (op)), s);
+
+  op1 = gimple_assign_rhs1 (s);
+  op2 = gimple_assign_rhs2 (s);
+
+  /* Simplify (X cmp Y) != 0 - (X cmp Y), and
+ (X cmp Y) == 0 - X cnp' Y, with cmp' = inverted cmp.  */
+  if (TREE_CODE_CLASS (hcode) == tcc_comparison)
+{
+  tree op1type = TREE_TYPE (op1);
+
+  if (code == EQ_EXPR)
+{
+ enum tree_code ncode;
+ ncode = invert_tree_comparison (hcode,
+ HONOR_NANS (TYPE_MODE (op1type)));
+ if (ncode != ERROR_MARK)
+   return make_new_tmp_statement (type, ncode, op1, op2, s);
+}
+  else
+return make_new_tmp_statement (type, hcode, op1, op2, s);
+}
+
+  /* Break up (X | Y) ==/!= 0 case.  */
+  if (hcode == BIT_IOR_EXPR)
+{
+  op1 = expand_cmp_ior (op1, type, code);
+  op2 = expand_cmp_ior (op2, type, code);
+  return make_new_tmp_statement (type, (code == EQ_EXPR ? BIT_AND_EXPR
+   : BIT_IOR_EXPR),
+op1, op2, s);
+}
+  return make_new_tmp_statement (type, code, op,
+build_zero_cst (TREE_TYPE (op)), s);
+}
+
+
 /* Break up STMT if it is a combined statement made out of
-   bitwise operations.  Handle expansion of ~(A op B).  */
+   bitwise operations.  Handle expansion of ~(A op B), and
+   (A | B) !=/== 0.  */

 static bool
 break_up_bitwise_combined_stmt (gimple stmt)
@@ -728,9 +811,13 @@ break_up_bitwise_combined_stmt (gimple s
   old_op1 = op1;
   old_op2 = op2 = NULL_TREE;

+  if (code == EQ_EXPR || code == NE_EXPR)
+old_op2 = op2 = gimple_assign_rhs2 (stmt);
+
   /* Check that CODE can be handled and that left-hand operand
  is of kind SSA_NAME.  */
-  if (code

<    1   2   3   4   5   6   7   8   >