RE: [PATCH, ifcvt] Check size cost in noce_try_store_flag_mask

2014-10-31 Thread Zhenqiang Chen
Thank you all for the comments. Patch is updated.

Bootstrap and no make check regression on X86-64.
No make check regression with Cortex-M0 qemu.
No performance changes for coremark, dhrystone, spec2000 and spec2006 on
X86-64 and Cortex-A15.

For CSiBE, ARM Cortex-M0 result is a little better. A little regression for
MIPS (less than 0.01%).

diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index 653653f..7bb2578 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -1393,6 +1393,9 @@ noce_try_store_flag_mask (struct noce_if_info
*if_info)
 
   if (target)
{
+ int old_cost, new_cost, insn_cost;
+ int speed_p;
+
  if (target != if_info-x)
noce_emit_move_insn (if_info-x, target);
 
@@ -1400,6 +1403,14 @@ noce_try_store_flag_mask (struct noce_if_info
*if_info)
  if (!seq)
return FALSE;
 
+ speed_p = optimize_bb_for_speed_p (BLOCK_FOR_INSN
(if_info-insn_a));
+ insn_cost = insn_rtx_cost (PATTERN (if_info-insn_a), speed_p);
+ old_cost = COSTS_N_INSNS (if_info-branch_cost) + insn_cost;
+ new_cost = seq_cost (seq, speed_p);
+
+ if (new_cost  old_cost)
+   return FALSE;
+
  emit_insn_before_setloc (seq, if_info-jump,
   INSN_LOCATION (if_info-insn_a));
  return TRUE;
diff --git a/gcc/testsuite/gcc.target/arm/ifcvt-size-check.c
b/gcc/testsuite/gcc.target/arm/ifcvt-size-check.c
new file mode 100644
index 000..43fa16b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/ifcvt-size-check.c
@@ -0,0 +1,13 @@
+/* { dg-do assemble } */
+/* { dg-options -mthumb -Os  }  */
+/* { dg-require-effective-target arm_thumb1_ok } */
+
+int
+test (unsigned char iov_len, int count, int i) {
+  unsigned char bytes = 0;
+  if ((unsigned char) ((char) 127 - bytes)  iov_len)
+return 22;
+  return 0;
+}
+/* { dg-final { object-size text = 12 } } */


 -Original Message-
 From: Jeff Law [mailto:l...@redhat.com]
 Sent: Thursday, October 30, 2014 1:27 PM
 To: Zhenqiang Chen; gcc-patches@gcc.gnu.org
 Subject: Re: [PATCH, ifcvt] Check size cost in noce_try_store_flag_mask
 
 On 10/26/14 19:53, Zhenqiang Chen wrote:
  Hi,
 
  Function noce_try_store_flag_mask converts if (test) x = 0; to x =
  -(test == 0);
 
  But from code size view, x = -(test == 0); might have more
  instructions than if (test) x = 0;. The patch checks the cost to
  determine the conversion is valuable or not.
 
  Bootstrap and no make check regression on X86-64.
  No make check regression with Cortex-M0 qemu.
  For CSiBE, ARM Cortex-m0 result is a little better. A little
  regression for MIPS. Roughly no change for PowerPC.
 
  OK for trunk?
 
  Thanks!
  -Zhenqiang
 
  ChangeLog:
  2014-10-27  Zhenqiang Chen  zhenqiang.c...@arm.com
 
  * ifcvt.c (noce_try_store_flag_mask): Check rtx cost.
 
  testsuite/ChangeLog:
  2014-10-27  Zhenqiang Chen  zhenqiang.c...@arm.com
 
  * gcc.target/arm/ifcvt-size-check.c: New test.
 
  diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 949d2b4..3abd518 100644
  --- a/gcc/ifcvt.c
  +++ b/gcc/ifcvt.c
  @@ -1393,6 +1393,14 @@ noce_try_store_flag_mask (struct noce_if_info
  *if_info)
if (!seq)
  return FALSE;
 
  + if (optimize_function_for_size_p (cfun))
  +   {
  + int old_cost = COSTS_N_INSNS (if_info-branch_cost + 1);
  + int new_cost = seq_cost (seq, 0);
  + if (new_cost  old_cost)
  +   return FALSE;
  +   }
  +
 As Andrew pointed out, there's really no reason to limit this to cases
where
 we're optimizing for size.  So that check should be removed.
 
 You should also engage with Michael to determine if the MIPS regressions
 are significant enough to warrant deeper investigation.  My gut tells me
that
 if MIPS is regressing because of this, then that's going to be an issue in
the
 MIPS costing model that the MIPS folks will ultimately need to fix.
 
 jeff
 






Re: [PATCH, ifcvt] Check size cost in noce_try_store_flag_mask

2014-10-31 Thread Andrew Pinski
On Thu, Oct 30, 2014 at 11:30 PM, Zhenqiang Chen zhenqiang.c...@arm.com wrote:
 Thank you all for the comments. Patch is updated.

 Bootstrap and no make check regression on X86-64.
 No make check regression with Cortex-M0 qemu.
 No performance changes for coremark, dhrystone, spec2000 and spec2006 on
 X86-64 and Cortex-A15.

 For CSiBE, ARM Cortex-M0 result is a little better. A little regression for
 MIPS (less than 0.01%).

I think I have a fix for MIPS which I need to submit too.  The problem
is IF_THEN_ELSE is not implemented for mips_rtx_costs.

Something like the attached one (though It is not updated for the new
cores including octeon3).

Thanks,
Andrew Pinski


 diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
 index 653653f..7bb2578 100644
 --- a/gcc/ifcvt.c
 +++ b/gcc/ifcvt.c
 @@ -1393,6 +1393,9 @@ noce_try_store_flag_mask (struct noce_if_info
 *if_info)

if (target)
 {
 + int old_cost, new_cost, insn_cost;
 + int speed_p;
 +
   if (target != if_info-x)
 noce_emit_move_insn (if_info-x, target);

 @@ -1400,6 +1403,14 @@ noce_try_store_flag_mask (struct noce_if_info
 *if_info)
   if (!seq)
 return FALSE;

 + speed_p = optimize_bb_for_speed_p (BLOCK_FOR_INSN
 (if_info-insn_a));
 + insn_cost = insn_rtx_cost (PATTERN (if_info-insn_a), speed_p);
 + old_cost = COSTS_N_INSNS (if_info-branch_cost) + insn_cost;
 + new_cost = seq_cost (seq, speed_p);
 +
 + if (new_cost  old_cost)
 +   return FALSE;
 +
   emit_insn_before_setloc (seq, if_info-jump,
INSN_LOCATION (if_info-insn_a));
   return TRUE;
 diff --git a/gcc/testsuite/gcc.target/arm/ifcvt-size-check.c
 b/gcc/testsuite/gcc.target/arm/ifcvt-size-check.c
 new file mode 100644
 index 000..43fa16b
 --- /dev/null
 +++ b/gcc/testsuite/gcc.target/arm/ifcvt-size-check.c
 @@ -0,0 +1,13 @@
 +/* { dg-do assemble } */
 +/* { dg-options -mthumb -Os  }  */
 +/* { dg-require-effective-target arm_thumb1_ok } */
 +
 +int
 +test (unsigned char iov_len, int count, int i) {
 +  unsigned char bytes = 0;
 +  if ((unsigned char) ((char) 127 - bytes)  iov_len)
 +return 22;
 +  return 0;
 +}
 +/* { dg-final { object-size text = 12 } } */


 -Original Message-
 From: Jeff Law [mailto:l...@redhat.com]
 Sent: Thursday, October 30, 2014 1:27 PM
 To: Zhenqiang Chen; gcc-patches@gcc.gnu.org
 Subject: Re: [PATCH, ifcvt] Check size cost in noce_try_store_flag_mask

 On 10/26/14 19:53, Zhenqiang Chen wrote:
  Hi,
 
  Function noce_try_store_flag_mask converts if (test) x = 0; to x =
  -(test == 0);
 
  But from code size view, x = -(test == 0); might have more
  instructions than if (test) x = 0;. The patch checks the cost to
  determine the conversion is valuable or not.
 
  Bootstrap and no make check regression on X86-64.
  No make check regression with Cortex-M0 qemu.
  For CSiBE, ARM Cortex-m0 result is a little better. A little
  regression for MIPS. Roughly no change for PowerPC.
 
  OK for trunk?
 
  Thanks!
  -Zhenqiang
 
  ChangeLog:
  2014-10-27  Zhenqiang Chen  zhenqiang.c...@arm.com
 
  * ifcvt.c (noce_try_store_flag_mask): Check rtx cost.
 
  testsuite/ChangeLog:
  2014-10-27  Zhenqiang Chen  zhenqiang.c...@arm.com
 
  * gcc.target/arm/ifcvt-size-check.c: New test.
 
  diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 949d2b4..3abd518 100644
  --- a/gcc/ifcvt.c
  +++ b/gcc/ifcvt.c
  @@ -1393,6 +1393,14 @@ noce_try_store_flag_mask (struct noce_if_info
  *if_info)
if (!seq)
  return FALSE;
 
  + if (optimize_function_for_size_p (cfun))
  +   {
  + int old_cost = COSTS_N_INSNS (if_info-branch_cost + 1);
  + int new_cost = seq_cost (seq, 0);
  + if (new_cost  old_cost)
  +   return FALSE;
  +   }
  +
 As Andrew pointed out, there's really no reason to limit this to cases
 where
 we're optimizing for size.  So that check should be removed.

 You should also engage with Michael to determine if the MIPS regressions
 are significant enough to warrant deeper investigation.  My gut tells me
 that
 if MIPS is regressing because of this, then that's going to be an issue in
 the
 MIPS costing model that the MIPS folks will ultimately need to fix.

 jeff







gcc.git-f37a94987366f2464c7122fa66b8f50797a26f11.patch
Description: Binary data


Re: [Patch, MIPS] Add Octeon3 support

2014-10-31 Thread Hurugalawadi, Naveen
Hi Catherine,

 Would you please add some testcases and resubmit your patch?

Thanks for the review and suggestions.
Added the testcase gcc.target/mips/octeon3-pipe-1.c

Please review the modified patch and let us know if its good.

Thanks,
Naveen

2014-10-31  Andrew Pinski  apin...@cavium.com

* config/mips/mips-cpus.def (octeon3): New cpu.
* config/mips/mips.c (mips_rtx_cost_data): Add octeon3.
(mips_print_operand case 'T', case 't'): Fix a bug as the mode
of the comparison no longer matches mode of the operands.
(mips_issue_rate): Handle PROCESSOR_OCTEON3.
* config/mips/mips.h (TARGET_OCTEON):  Add Octeon3.
(TARGET_OCTEON2): Likewise.
(TUNE_OCTEON): Add Octeon3.
* config/mips/mips.md (processor): Add octeon3.
* config/mips/octeon.md (octeon_fpu): New automaton and cpu_unit.
(octeon_arith): Add octeon3.
(octeon_condmove): Remove.
(octeon_condmove_o1): New reservation.
(octeon_condmove_o2): New reservation.
(octeon_condmove_o3_int_on_cc): New reservation.
(octeon_load_o2): Add octeon3.
(octeon_cop_o2): Likewise.
(octeon_store): Likewise.
(octeon_brj_o2): Likewise.
(octeon_imul3_o2): Likewise.
(octeon_imul_o2): Likewise.
(octeon_mfhilo_o2): Likewise.
(octeon_imadd_o2): Likewise.
(octeon_idiv_o2_si): Likewise.
(octeon_idiv_o2_di): Likewise.
(octeon_fpu): Add to the automaton.
(octeon_fpu): New cpu unit.
(octeon_condmove_o2): Check for non floating point modes.
(octeon_load_o2): Add prefetchx.
(octeon_cop_o2): Don't check for octeon3.
(octeon3_faddsubcvt): New reservation.
(octeon3_fmul): Likewise.
(octeon3_fmadd): Likewise.
(octeon3_div_sf): Likewise.
(octeon3_div_df): Likewise.
(octeon3_sqrt_sf): Likewise.
(octeon3_sqrt_df): Likewise.
(octeon3_rsqrt_sf): Likewise.
(octeon3_rsqrt_df): Likewise.
(octeon3_fabsnegmov): Likewise.
(octeon_fcond): Likewise.
(octeon_fcondmov): Likewise.
(octeon_fpmtc1): Likewise.
(octeon_fpmfc1): Likewise.
(octeon_fpload): Likewise.
(octeon_fpstore): Likewise.
* config/mips/mips-tables.opt: Regenerate.
* doc/invoke.texi (-march=@var{arch}): Add octeon3.

2014-10-31  Naveen H.S  naveen.hurugalaw...@caviumnetworks.com

* gcc.target/mips/octeon3-pipe-1.c: New test.diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 28ae552..77455a2 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,54 @@
+2014-10-31  Andrew Pinski  apin...@cavium.com
+
+	* config/mips/mips-cpus.def (octeon3): New cpu.
+	* config/mips/mips.c (mips_rtx_cost_data): Add octeon3.
+	(mips_print_operand case 'T', case 't'): Fix a bug as the mode
+	of the comparison no longer matches mode of the operands.
+	(mips_issue_rate): Handle PROCESSOR_OCTEON3.
+	* config/mips/mips.h (TARGET_OCTEON):  Add Octeon3.
+	(TARGET_OCTEON2): Likewise.
+	(TUNE_OCTEON): Add Octeon3.
+	* config/mips/mips.md (processor): Add octeon3.
+	* config/mips/octeon.md (octeon_fpu): New automaton and cpu_unit.
+	(octeon_arith): Add octeon3.
+	(octeon_condmove): Remove.
+	(octeon_condmove_o1): New reservation.
+	(octeon_condmove_o2): New reservation.
+	(octeon_condmove_o3_int_on_cc): New reservation.
+	(octeon_load_o2): Add octeon3.
+	(octeon_cop_o2): Likewise.
+	(octeon_store): Likewise.
+	(octeon_brj_o2): Likewise.
+	(octeon_imul3_o2): Likewise.
+	(octeon_imul_o2): Likewise.
+	(octeon_mfhilo_o2): Likewise.
+	(octeon_imadd_o2): Likewise.
+	(octeon_idiv_o2_si): Likewise.
+	(octeon_idiv_o2_di): Likewise.
+	(octeon_fpu): Add to the automaton.
+	(octeon_fpu): New cpu unit.
+	(octeon_condmove_o2): Check for non floating point modes.
+	(octeon_load_o2): Add prefetchx.
+	(octeon_cop_o2): Don't check for octeon3.
+	(octeon3_faddsubcvt): New reservation.
+	(octeon3_fmul): Likewise.
+	(octeon3_fmadd): Likewise.
+	(octeon3_div_sf): Likewise.
+	(octeon3_div_df): Likewise.
+	(octeon3_sqrt_sf): Likewise.
+	(octeon3_sqrt_df): Likewise.
+	(octeon3_rsqrt_sf): Likewise.
+	(octeon3_rsqrt_df): Likewise.
+	(octeon3_fabsnegmov): Likewise.
+	(octeon_fcond): Likewise.
+	(octeon_fcondmov): Likewise.
+	(octeon_fpmtc1): Likewise.
+	(octeon_fpmfc1): Likewise.
+	(octeon_fpload): Likewise.
+	(octeon_fpstore): Likewise.
+	* config/mips/mips-tables.opt: Regenerate.
+	* doc/invoke.texi (-march=@var{arch}): Add octeon3.
+
 2014-10-10  Felix Yang  felix.y...@huawei.com
 
 	* config/xtensa/xtensa.h (TARGET_LOOPS): New Macro.
diff --git a/gcc/config/mips/mips-cpus.def b/gcc/config/mips/mips-cpus.def
index d5528d3..e2985b8 100644
--- a/gcc/config/mips/mips-cpus.def
+++ b/gcc/config/mips/mips-cpus.def
@@ -162,4 +162,5 @@ MIPS_CPU (loongson3a, PROCESSOR_LOONGSON_3A, 65, PTF_AVOID_BRANCHLIKELY)
 MIPS_CPU (octeon, PROCESSOR_OCTEON, 65, PTF_AVOID_BRANCHLIKELY)
 MIPS_CPU (octeon+, PROCESSOR_OCTEON, 65, 

[PATCH] x86: allow to suppress default clobbers added to asm()s

2014-10-31 Thread Jan Beulich
While it always seemed wrong to me that there's no way to avoid the
default flags and fpsr clobbers, the regression the fix for
PR/60663 introduced (see PR/63637) makes it even more desirable to have
such a mechanism: This way, at least asm()s with a single output and no
explicit clobbers can again be made subject to CSE.

gcc:
2014-10-31  Jan Beulich  jbeul...@suse.com

* config/i386/i386.c (ix86_target_string): Add
-mno-default-asm-clobbers.
(ix86_valid_target_attribute_inner_p): Handle
-m{,no-}default-asm-clobbers.
(ix86_md_asm_clobbers): Handle inverse clobbers.
* config/i386/i386.h (NOCC_REGNUM, NOFPSR_REGNUM): Define.
(ADDITIONAL_REGISTER_NAMES): Add cc, !cc, !flags, and
!fpsr.
* config/i386/i386.opt: Add mdefault-asm-clobbers and
mno-default-asm-clobbers.
* varasm.c (decode_reg_name_and_count): Permit negative
register numbers in ADDITIONAL_REGISTER_NAMES.

gcc/testsuite:
2014-10-31  Jan Beulich  jbeul...@suse.com

* gcc.target/i386/20060218-1.c: Adjust expected error.
* gcc.target/i386/invclbr[123].c: New.

--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -2664,6 +2664,7 @@ ix86_target_string (HOST_WIDE_INT isa, i
 { -minline-stringops-dynamically,
MASK_INLINE_STRINGOPS_DYNAMICALLY },
 { -mms-bitfields,MASK_MS_BITFIELD_LAYOUT },
 { -mno-align-stringops,  MASK_NO_ALIGN_STRINGOPS },
+{ -mno-default-asm-clobbers, MASK_NO_DEFAULT_ASM_CLOBBERS },
 { -mno-fancy-math-387,   MASK_NO_FANCY_MATH_387 },
 { -mno-push-args,MASK_NO_PUSH_ARGS },
 { -mno-red-zone, MASK_NO_RED_ZONE },
@@ -4649,6 +4650,10 @@ ix86_valid_target_attribute_inner_p (tre
  OPT_mno_align_stringops,
  MASK_NO_ALIGN_STRINGOPS),
 
+IX86_ATTR_NO (default-asm-clobbers,
+ OPT_mno_default_asm_clobbers,
+ MASK_NO_DEFAULT_ASM_CLOBBERS),
+
 IX86_ATTR_YES (recip,
   OPT_mrecip,
   MASK_RECIP),
@@ -44165,10 +44170,31 @@ ix86_c_mode_for_suffix (char suffix)
 static tree
 ix86_md_asm_clobbers (tree, tree, tree clobbers)
 {
-  clobbers = tree_cons (NULL_TREE, build_string (5, flags),
-   clobbers);
-  clobbers = tree_cons (NULL_TREE, build_string (4, fpsr),
-   clobbers);
+  tree clobber;
+  bool flags_used = false, fpsr_used = false;
+  bool nocc_used = false, nofpsr_used = false;
+
+  if (!TARGET_DEFAULT_ASM_CLOBBERS)
+return clobbers;
+
+  for (clobber = clobbers; clobber; clobber = TREE_CHAIN (clobber))
+switch (decode_reg_name (TREE_STRING_POINTER (TREE_VALUE (clobber
+  {
+  case FLAGS_REG: flags_used  = true; break;
+  case FPSR_REG:  fpsr_used   = true; break;
+  case NOCC_REGNUM:   nocc_used   = true; break;
+  case NOFPSR_REGNUM: nofpsr_used = true; break;
+  }
+
+  if ((flags_used  nocc_used) || (fpsr_used  nofpsr_used))
+error (conflicting clobbers in %asm%);
+
+  if (!flags_used  !nocc_used)
+clobbers = tree_cons (NULL_TREE, build_string (5, flags),
+ clobbers);
+  if (!fpsr_used  !nofpsr_used)
+clobbers = tree_cons (NULL_TREE, build_string (4, fpsr),
+ clobbers);
   return clobbers;
 }
 
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -1242,6 +1242,11 @@ extern const char *host_detect_local_cpu
  ? INVALID_REGNUM  \
  : REAL_PIC_OFFSET_TABLE_REGNUM)
 
+/* Fake register numbers to be used as inverse asm() clobber specifiers.
+   Any negative numbers below the range used by decode_reg_name () will do.  */
+#define NOCC_REGNUM   (-127)
+#define NOFPSR_REGNUM (-126)
+
 #define GOT_SYMBOL_NAME _GLOBAL_OFFSET_TABLE_
 
 /* This is overridden by cygwin.h.  */
@@ -2059,7 +2064,9 @@ do {  
\
   { zmm16, 53}, { zmm17, 54}, { zmm18, 55}, { zmm19, 56},  \
   { zmm20, 57}, { zmm21, 58}, { zmm22, 59}, { zmm23, 60},  \
   { zmm24, 61}, { zmm25, 62}, { zmm26, 63}, { zmm27, 64},  \
-  { zmm28, 65}, { zmm29, 66}, { zmm30, 67}, { zmm31, 68} }
+  { zmm28, 65}, { zmm29, 66}, { zmm30, 67}, { zmm31, 68},  \
+  { cc, FLAGS_REG }, { !cc, NOCC_REGNUM }, \
+  { !flags, NOCC_REGNUM }, { !fpsr, NOFPSR_REGNUM } }
 
 /* Note we are omitting these since currently I don't know how
 to get gcc to use these, since they want the same but different
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -287,6 +287,10 @@ Enum(pmode) String(long) Value(PMODE_DI)
 mcpu=
 Target RejectNegative Joined Undocumented Alias(mtune=) Warn(%-mcpu=% is 
deprecated; use %-mtune=% or %-march=% instead)
 
+mdefault-asm-clobbers
+Target RejectNegative Report InverseMask(NO_DEFAULT_ASM_CLOBBERS, 
DEFAULT_ASM_CLOBBERS) Undocumented Save
+Attach 

Re: genmatch infinite loop during bootstrap on AIX

2014-10-31 Thread Richard Biener
On Thu, 30 Oct 2014, David Edelsohn wrote:

 On Thu, Oct 30, 2014 at 4:51 AM, Richard Biener
 richard.guent...@gmail.com wrote:
  On Wed, Oct 29, 2014 at 6:13 PM, David Edelsohn dje@gmail.com wrote:
  On Wed, Oct 29, 2014 at 9:24 AM, Richard Biener
  richard.guent...@gmail.com wrote:
 
  Because only genmatch calls functions from libstdc++.  Btw, why
  would genmatch miscompile an empty function or the call to it?
 
  I tried bootstrapping with libstdc++ built without the AIX ld -G
  flag and that is succeeding.
 
  -G produces a shared object for use with SVR4-style runtime linking,
  so this version of libstdc++ no longer allows runtime function
  interposition, e.g., operator new, although it is not used frequently.
  Something about the GCC-produced tail calls is interacting badly with
  that feature.
 
  Note that this makes GCC bootstrap on AIX very fragile at the moment
  because it depends on how libstdc++ was built in previous releases.  I
  can bootstrap with GCC 4.6.3 and 4.8.1 but not with 4.7.3, 4.8.0, nor
  4.9.0.  A problematic libstdc++ from earlier releases causes genmatch
  to loop in stage 1.
 
  I see.  A bootstrap with IPA ICF disabled did not succeed but runs into
  the same issue in stage2.  So I wonder if the issue is latent for much
  longer and genmatch just exposes it now.
 
  I'll see if I can remove the use of std::map from genmatch as a
  workaround.
 
 I assume that this is a pervasive issue in the interaction between GCC
 optimizations and AIX -G linker option. Something expects the second
 call to point to a different implementation. I don't know if the
 address in the TOC (GOT) is wrong or something expects the second call
 to use a different TOC, but there is a circular reference.
 
 I am going to apply a patch to GCC to not build libstdc++ with -G.  I
 also will apply it to GCC 4.9 branch.  I was hoping that it could be
 included in GCC 4.9.2, but I needed to test it thoroughly and Jakub
 beat me with the release.

As it might only affect static linking(?) it might be a good idea to
run the libstdc++ testsuite with statically linking libstdc++
(-static-libstdc++) before/after such change?

That is,

make check-target-libstdc++-v3 
RUNTESTFLAGS=--target_board=unix/-static-libstdc++

(hopefully that is able to add to link flags and not compile-flags only)

Thanks,
Richard.


[match-and-simplify] Merge from trunk

2014-10-31 Thread Richard Biener

2014-10-31  Richard Biener  rguent...@suse.de

Merge from trunk rr216800 through r215940.

Brings back next merge piece.



Re: add warning for unused user-defined operator

2014-10-31 Thread Richard Biener
On Thu, Oct 30, 2014 at 6:49 PM, Prathamesh Kulkarni
bilbotheelffri...@gmail.com wrote:
 On Thu, Oct 30, 2014 at 11:12 PM, Prathamesh Kulkarni
 bilbotheelffri...@gmail.com wrote:
 On Tue, Oct 28, 2014 at 3:38 PM, Richard Biener
 richard.guent...@gmail.com wrote:
 On Sat, Oct 25, 2014 at 12:38 PM, Prathamesh Kulkarni
 bilbotheelffri...@gmail.com wrote:
 Add warning for unused user-defined operator in for.

 Issues:
 a) I added a new field used in user_id, which is initially false,
 and is set to true, when it is looked up using get_operator(). Not sure
 if that's a good idea.

 Sure - that's the simplest way.

 b) error_cb determines whether to exit depending on second
 argument, and does not if it equals CPP_DL_WARNING.
 I am not sure what to return from error_cb, I just put return 0.

 Yeah, I suppose that works.  The return parameter doesn't seem to be
 documented anywhere.

 During the build it gives the following warning:
 ../../src/gcc/match.pd:64:6 warning: operator op defined but not used
 (for op (ceil_mod floor_mod round_mod trunc_mod)
   ^

 * genmatch.c
   (error_cb): Adjust to print warnings.
   (warning_at): New function.
   (user_id): Add new member used.
   (get_operator): Adjust to changes in user_id.
   (parse_for): Warn for unused operators.

 Looks good.  I'll apply this later after merging from trunk again.

 Please watch out for added trailing spaces like here on the 2nd line

 -error_cb (cpp_reader *, int, int, source_location location,
 - unsigned int, const char *msg, va_list *ap)
 +error_cb (cpp_reader *, int errtype, int, source_location location,
 + unsigned int, const char *msg, va_list *ap)

 and long lines like

 +  fprintf (stderr, %s:%d:%d %s: , loc.file, loc.line, loc.column,
 (errtype == CPP_DL_WARNING) ? warning : error);

 As well as spurious whitespace changes like

  }

 +
  static void

 The following is what I have applied.
 It warns defined but not used if the operator is used in c_expr.
 eg (artificial pattern):
 (for op (plus minus)
   op2 (mult trunc_div)
   (op @x @y)
   { op2; })

 The following patch fixes that.

 * genmatch.c
   (parser::parse_c_expr): Mark operator as used.
 Oops, I had forgotten get_operator marks operator as used.
 We then only need to call get_operator.

 * genmatch.c
   (parser::parse_c_expr): Call get_operator.

Thanks, applied.  (please post patches to gcc-patches)

Richard.

 Thanks,
 Prathamesh

 Thanks,
 Prathamesh

 Thanks,
 Richard.

 2014-10-28  Prathamesh Kulkarni  bilbotheelffri...@gmail.com

 * genmatch.c (error_cb): Adjust for printing warnings.
 (warning_at): New function.
 (user_id): Add new member used.
 (get_operator): Mark user_id as used.
 (parse_for): Warn for unused operators.


 Thanks,
 Prathamesh


Re: [gofrontend-dev] Re: [PATCH 7/9] Gccgo port to s390[x] -- part I

2014-10-31 Thread Dominik Vogt
On Thu, Oct 30, 2014 at 08:20:20AM -0700, Ian Taylor wrote:
  /* { dg-skip-if not supported for target { ! s390*-*-* x86_64-*-* } } */
 +/* { dg-skip-if not supported for target { ! lp64 } } */

Hm, but then the test will be skipped on s390 (31 bit) too where
it should work.  The current solution is hopefully good enough for
now, but maybe boolean operators in the selector can help to
improve it; I'll check that, but give me some time for more
important issues first.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany



Re: [gofrontend-dev] Re: [PATCH 7/9] Gccgo port to s390[x] -- part I

2014-10-31 Thread Dominik Vogt
On Thu, Oct 30, 2014 at 07:51:45AM -0700, Ian Taylor wrote:
 On Thu, Oct 30, 2014 at 12:25 AM, Dominik Vogt v...@linux.vnet.ibm.com 
 wrote:
  See attached patch.
 
 I don't mind skipping the test on other platforms, but xfail is not
 correct.  When an xfail test passes, we get an XPASS error from the
 testsuite.  We need dg-skip-if.  I committed this patch.

That is exactly the reason why I chose dg-xfail-if:  To identify
the targets where the test works out of the box, because I think
there won't be many of them.

But anyway, we can leave it as it is for the moment and eventually
I'll get around cleaning that up.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany



Re: [PATCH] Optimize UBSAN_NULL checks

2014-10-31 Thread Marek Polacek
On Thu, Oct 30, 2014 at 07:47:52PM +0100, Marek Polacek wrote:
 This patch tries to optimize away redundant UBSAN_NULL checks.
 It walks the statements, looks for UBSAN_NULL calls and keeps
 track of pointers and statements checking that pointer in a
 hash map.  Now, if we can prove that some UBSAN_NULL stmt is
 dominated by other one which requires the same or less strict
 alignment, there's no point in keeping this check around and
 expanding it.
 
 optimize_checks should be enhanced to handle other {ub,a,t}san
 checks as well - which is what I'm going to work on next.

(Strike this version.  I'm working on a variant that walks the dominator
tree first to get better optimizations.)

Marek


[committed] MAINTAINERS: add myself to write-after-approval list

2014-10-31 Thread Ilya Enkovich
2014-10-31  Ilya Enkovich  ilya.enkov...@intel.com

* MAINTAINERS (Write After Approval): Add myself.

Index: MAINTAINERS
===
--- MAINTAINERS (revision 216948)
+++ MAINTAINERS (revision 216952)
@@ -373,6 +373,7 @@
 Bernd Edlinger bernd.edlin...@hotmail.de
 Phil Edwards   p...@gcc.gnu.org
 Mohan Embargnust...@thisiscool.com
+Ilya Enkovich  enkovich@gmail.com
 Revital Eres   e...@il.ibm.com
 Marc Espie es...@cvs.openbsd.org
 Ansgar Esztermann  
ans...@thphy.uni-duesseldorf.de


[PATCH, IPA ICF] Fix PR63696.

2014-10-31 Thread Maxim Ostapenko

Hi,

this tiny patch fixes PR63696 (alloc-dealloc-mismatch in ipa-icf.c).

Tested on x86_64-unknown-linux-gnu, ok to commit?

-Maxim
gcc/ChangeLog:

2014-10-31  Max Ostapenko  m.ostape...@partner.samsung.com

	* ipa-icf.c (sem_function::~sem_function): Change free to delete to avoid
	alloc-dealloc mismatch with new, called in ipa_icf::sem_function::init.

diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index 975894b..a278a62 100644
--- a/gcc/ipa-icf.c
+++ b/gcc/ipa-icf.c
@@ -216,7 +216,7 @@ sem_function::sem_function (cgraph_node *node, hashval_t hash,
 sem_function::~sem_function ()
 {
   for (unsigned i = 0; i  bb_sorted.length (); i++)
-free (bb_sorted[i]);
+delete (bb_sorted[i]);
 
   arg_types.release ();
   bb_sizes.release ();


RE: [PATCH 2/X, i386, PR54232] Enable EBX for x86 in 32bits PIC code

2014-10-31 Thread Zamyatin, Igor
 
 Those macros use =b etc. in asm constraints, so IMHO you'll get the same
 error as for say:
 
 int
 foo (void)
 {
   bar ();
   int i = 0;
   asm volatile ( : +b (i));
   bar ();
   return i;
 }
 
 when compiled by gcc 4.9 and earlier with -O2 -m32 -fpic:
 error: inconsistent operand constraints in an ‘asm’

I see, thanks!

Fixed patch is here - https://sourceware.org/ml/libc-alpha/2014-10/msg00746.html

Igor

 
   Jakub


Re: [PATCH, IPA ICF] Fix PR63696.

2014-10-31 Thread Yury Gribov

On 10/31/2014 11:35 AM, Maxim Ostapenko wrote:

Hi,

this tiny patch fixes PR63696 (alloc-dealloc-mismatch in ipa-icf.c).

Tested on x86_64-unknown-linux-gnu, ok to commit?


Could you add PR comment to ChangeLog?

-Y


RE: [Ping] [PATCH, 4/10] expand ccmp

2014-10-31 Thread Zhenqiang Chen


 -Original Message-
 From: Richard Henderson [mailto:r...@redhat.com]
 Sent: Thursday, October 30, 2014 11:58 PM
 To: Zhenqiang Chen
 Cc: gcc-patches@gcc.gnu.org
 Subject: Re: [Ping] [PATCH, 4/10] expand ccmp
 
 On 10/29/2014 03:30 AM, Zhenqiang Chen wrote:
  +
  +bool
  +ccmp_insn_p (rtx object)
  +{
  +  rtx x = PATTERN (object);
  +  if (targetm.gen_ccmp_first
  +   GET_CODE (x) == SET
  +   GET_CODE (XEXP (x, 1)) == COMPARE
  +   (GET_CODE (XEXP (XEXP (x, 1), 0)) == IOR
  + || GET_CODE (XEXP (XEXP (x, 1), 0)) == AND))
  +return true;
  +  return false;
  +}
  +
 
 With the ifcvt changes I requested, I believe this is now unused.

Yes. No one uses ccmp_insn_p. Removed from ccmp.{h, c}.
 
  +}
  +rtx
  +expand_ccmp_expr (gimple g)
 
 Watch your spacing.  And you're missing the comment before the function.

Updated.

Thanks!
-Zhenqiang
 
 Otherwise ok.
 
 
 r~


3-4-ccmp.patch
Description: Binary data


Re: [PATCH AVX512] Fix dg.torture tests with avx512

2014-10-31 Thread Uros Bizjak
On Thu, Oct 30, 2014 at 3:55 PM, Ilya Tocar tocarip.in...@gmail.com wrote:
 Hi,

 I've run gcc.dg/torture/* tests with -mavx512bw -mavx512vl -mavx512dq
 flags, and got a bunch of fails (mostly in permutes autogen).
 Patch below fixes them.
 Ok for trunk?

 2014-10-30  Ilya Tocar  ilya.to...@intel.com

 * config/i386/i386.c (expand_vec_perm_pshufb): Try vpermq/vpermd
 for 512-bit wide modes.
 (expand_vec_perm_1): Use correct versions of patterns.
 * config/i386/sse.md (avx512f_vec_dup_mode_1): New.
 (vashrmode3mask_name): Split V8HImode and V16QImode.

Please name new patterns ..._vec_dupmode... , without space between
vec_dup and mode.

 ---
  gcc/config/i386/i386.c | 59 
 --
  gcc/config/i386/sse.md | 54 ++---
  2 files changed, 98 insertions(+), 15 deletions(-)

 diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
 index 71a4f6a..74ff894 100644
 --- a/gcc/config/i386/i386.c
 +++ b/gcc/config/i386/i386.c
 @@ -45889,6 +45889,42 @@ expand_vec_perm_pshufb (struct expand_vec_perm_d *d)
 {
   if (!TARGET_AVX512BW)
 return false;
 +
 + /* If vpermq didn't work, vpshufb won't work either.  */
 + if (d-vmode == V8DFmode || d-vmode == V8DImode)
 +   return false;
 +
 + vmode = V64QImode;
 + if (d-vmode == V16SImode
 + || d-vmode == V32HImode
 + || d-vmode == V64QImode)
 +   {
 + /* First see if vpermq can be used for
 +V16SImode/V32HImode/V64QImode.  */
 + if (valid_perm_using_mode_p (V8DImode, d))
 +   {
 + for (i = 0; i  8; i++)
 +   perm[i] = (d-perm[i * nelt / 8] * 8 / nelt)  7;
 + if (d-testing_p)
 +   return true;
 + target = gen_reg_rtx (V8DImode);
 + if (expand_vselect (target, gen_lowpart (V8DImode, d-op0),
 + perm, 8, false))
 +   {
 + emit_move_insn (d-target,
 + gen_lowpart (d-vmode, target));
 + return true;
 +   }
 + return false;
 +   }
 +
 + /* Next see if vpermd can be used.  */
 + if (valid_perm_using_mode_p (V16SImode, d))
 +   vmode = V16SImode;
 +   }
 + /* Or if vpermps can be used.  */
 + else if (d-vmode == V16SFmode)
 +   vmode = V16SImode;
   if (vmode == V64QImode)
 {
   /* vpshufb only works intra lanes, it is not
 @@ -45908,6 +45944,9 @@ expand_vec_perm_pshufb (struct expand_vec_perm_d *d)
if (vmode == V8SImode)
  for (i = 0; i  8; ++i)
rperm[i] = GEN_INT ((d-perm[i * nelt / 8] * 8 / nelt)  7);
 +  else if (vmode == V16SImode)
 +for (i = 0; i  16; ++i)
 +  rperm[i] = GEN_INT ((d-perm[i * nelt / 16] * 16 / nelt)  15);
else
  {
eltsz = GET_MODE_SIZE (GET_MODE_INNER (d-vmode));


I'd like to ask Jakub for a review of the above two parts, other parts
are OK with a rename (as mentioned above).

Uros.


[ping*2] fix unwinding on e500 processors

2014-10-31 Thread Olivier Hainque
Hello,

ping for https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01369.html

a proposal to repair unwinding breakage on e500 targets.

The url above is that of the first ping, where the originally
submitted patch was splitted in two to facilitate review.

The original submission, with a more complete description of the
problem is at https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02625.html.

Thanks in advance for your feedback,

Olivier




Re: [PATCH][PPC] Skip gcc.target tests with conflicting -mcpu

2014-10-31 Thread Andrew Stubbs

On 30/10/14 18:37, Mike Stump wrote:

On Oct 30, 2014, at 10:25 AM, Andrew Stubbs a...@codesourcery.com
wrote:

Many of the tests in gcc.target/powerpc specify an explicit -mcpu
option with dg-options.


So, I think this isn’t the strategy people like for this sort of
thing.  The problem is default flags.  You can have a certain cpu as
a target but no flag for it, no flag, no way to skip based upon that
flag.


I'm not sure what that last sentence is trying to say?

Default flags (as in flags that you don't see) ought not to be a problem 
because an explicit flag should override them.


My problem is with the flags that select non-default multilibs. When you 
run a test you get compile line like this:


   target-gcc dg-options -mcpu=multilib-cpu foo.c

If dg-options contains only optimization options then all is well. If 
it contains an mcpu option then you get conflicting options. The last 
one will win, which will likely cause a test failure.


Extra test failures must be investigated, and when there's lot like this 
then that's a huge time-sink. Either that or a real failure gets missed.


This might not be the best solution, but I really don't like the status 
quo. If it's not this, what is it?



Also, I'm fairly dissatisfied with the current situation where a
test uses dg-require-effective-target to test the default target,
and then adds options that would change the result of that test; it
can cause a test to get skipped when actually it would work fine.
Anyway, that's a problem for a different day.


But, that code works the way you want it to?  If you don’t want to
add a flag, you don’t.


I don't think you understood me. Consider this scenario:

   /* { dg-require-effective-target powerpc_spe } */
   /* { dg-options -mcpu=8548 -mspe -mabi=spe } */

If the selected multilib happens to be one that does not support SPE, 
then this test will *not* be run, and yet, as soon as the dg-options 
have been applied then the target will support SPE (if the compiler has 
support at all).


The idiom appears repeatedly throughout the gcc.target tests. Anyway, I 
had not tried to fix this. I had just noted that it can lead to 
incomplete testing. It probably won't lead to false-fails unless 
conflicting mcpu options happen to make scan-assembler tests mismatch.


One possible solution to both problems is to rewrite the tests like this 
(and some tests do):


   /* { dg-options -mcpu=8548 -mspe -mabi=spe } */
   /* { dg-skip-if not an SPE target { ! powerpc_spe_nocache } { * 
} {  } } */


The downside is that nocache tests are much slower. It also requires 
that there is a suitable feature test available. If it just checks that 
the right cpu has been used then it's functionally identical to my 
dg-skip-if patch.


And this still has the problem that multiple -mcpu flags can cause the 
multilib selection to go wrong, which results in link errors.


Another possibility might be to invent dg-remove-options or 
dg-reset-options that removes any multilib-selection option. The test 
would run identically for all multilibs, but that's probably appropriate 
in these cases.


Thoughts?

Andrew


Re: [PATCH, IPA ICF] Fix PR63696.

2014-10-31 Thread Richard Biener
On Fri, Oct 31, 2014 at 9:35 AM, Maxim Ostapenko
m.ostape...@partner.samsung.com wrote:
 Hi,

 this tiny patch fixes PR63696 (alloc-dealloc-mismatch in ipa-icf.c).

 Tested on x86_64-unknown-linux-gnu, ok to commit?

Ok with referencing the PR from the changelog.

Thanks,
Richard.

 -Maxim


Re: [gomp4] OpenACC acc_on_device

2014-10-31 Thread Thomas Schwinge
Hi!

On Thu, 18 Sep 2014 20:01:02 +0200, I wrote:
 Here is my OpenACC acc_on_device patch, in a more complete form, with
 test cases and all that.
 
 On Wed, 17 Sep 2014 10:49:54 +0200, Jakub Jelinek ja...@redhat.com wrote:
  On Wed, Sep 17, 2014 at 10:44:12AM +0200, Tobias Burnus wrote:
   Cesar Philippidis wrote:
The patch introduces the following OpenACC/PTX-specific built-ins:
   ...
   
   It is not completely clear how they are supposed to get used. Should the
   user call them directly in some cases? Or are they only used internally?
   
   acc_on_device sounds like a function which would be in C/C++ made 
   available
   to the user via #define acc_on_device __builtin_acc_on_device.
  
  And not just providing acc_on_device prototype in some header?
 
 Yes, just a prototype.  And next to DEF_GOACC_BUILTIN (configured the
 same as DEF_GOMP_BUILTIN), I add a new DEF_GOACC_BUILTIN_COMPILER that is
 configured to always provide the __builtin_[...] variant, but the
 un-prefixed [...]  only if -fopenacc is in effect.  Does that look
 alright?
 
  Without
  looking at the OpenACC standard, it sounds like this function could be
  similar to omp_is_initial_device, so can and should be handled supposedly
  similarly.
 
 I think we've been talking about this at the Cauldron, where you agreed
 that omp_is_initial_device should also be implemented as a builtin.  (Or
 am I confusing things?)
 
   However, the rest looks as if it should rather be an internal function
   instead of a builtin. Or should the user really ever call the builtin
   directly?
  
  GOMP_* functions are builtins and not internal functions too, all those
  functions are library functions, while the user typically doesn't call them
  directly, they still are implemented in the library.  Internal functions are
  used for something that doesn't have a library implementation and is not
  something user can call directly.
 
   Regarding Fortran: Builtins aren't directly available to the user. You 
   have to
   wrap them into an intrinsic to make them available. If they have to be 
   made
   available via a module (e.g. via module acc) - you have to create a 
   virtual
   module, which provides the intrinsic. If you don't want to convert the 
   whole
   module, you could create an auxiliar module (e.g. acc_internal_) which 
   provides
   only those bits - and then include it (use,intrinsic :: ...) it in the
   main module - written in normal Fortran.
 
 This I have not yet addressed -- please see the TODO comments in the
 gcc/fortran/ files as well as Fortran test cases.
 
  For the user callable fortran functions, for OpenMP libgomp just provides
  *_ entrypoints to * functions.  Perhaps acc_on_device_ could be provided
  too.
 
 This is what I had done already.
 
 Does that patch look good?  (With the Fortran things still to be
 addressed.)

(Checked in, back then, to gomp-4_0-branch in r215506.)

   gcc/testsuite/
   * c-c++-common/goacc/acc_on_device-1.c: New file.
   * c-c++-common/goacc/acc_on_device-2.c: Likewise.
   * c-c++-common/goacc/acc_on_device-2-off.c: Likewise.

Here is a patch, checked in to gomp-4_0-branch in r216953, to make
acc_on_device-1.c C-only (implicitly declared functions are only
supported in C), and make the others actually fit for C++ -- and XFAIL
the C++ case.  How to resolve that one?

commit b1a009fdf340acf1840c1b6c9022be69a8f0a661
Author: tschwinge tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4
Date:   Fri Oct 31 10:39:44 2014 +

Make acc_on_device test cases fit for C++.

gcc/testsuite/
* c-c++-common/goacc/acc_on_device-1.c: Move...
* gcc.dg/goacc/acc_on_device-1.c: ... here.
(dg-additional-options): Add -std=c89.
* c-c++-common/goacc/acc_on_device-2-off.c: Extend for C++.
* c-c++-common/goacc/acc_on_device-2.c: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@216953 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/testsuite/ChangeLog.gomp |  8 
 gcc/testsuite/c-c++-common/goacc/acc_on_device-2-off.c   | 10 +-
 gcc/testsuite/c-c++-common/goacc/acc_on_device-2.c   | 16 ++--
 .../{c-c++-common = gcc.dg}/goacc/acc_on_device-1.c |  2 +-
 4 files changed, 32 insertions(+), 4 deletions(-)

diff --git gcc/testsuite/ChangeLog.gomp gcc/testsuite/ChangeLog.gomp
index 10232bc..2489b39 100644
--- gcc/testsuite/ChangeLog.gomp
+++ gcc/testsuite/ChangeLog.gomp
@@ -1,3 +1,11 @@
+2014-10-30  Thomas Schwinge  tho...@codesourcery.com
+
+   * c-c++-common/goacc/acc_on_device-1.c: Move...
+   * gcc.dg/goacc/acc_on_device-1.c: ... here.
+   (dg-additional-options): Add -std=c89.
+   * c-c++-common/goacc/acc_on_device-2-off.c: Extend for C++.
+   * c-c++-common/goacc/acc_on_device-2.c: Likewise.
+
 2014-10-20  Thomas Schwinge  tho...@codesourcery.com
 
* gcc.dg/goacc/sb-1.c: Move file...
diff --git 

Re: [PATCH] Fix PR63259: bswap not recognized when finishing with rotation

2014-10-31 Thread Richard Biener
On Wed, Oct 29, 2014 at 2:30 PM, Thomas Preud'homme
thomas.preudho...@arm.com wrote:
 From: Richard Biener [mailto:richard.guent...@gmail.com]
 Sent: Wednesday, October 08, 2014 8:27 AM

 I wouldn't worry about that too much.  Indeed the question would be
 what
 should be canonical on GIMPLE (expanders should choose the optimal
 vairant from both).  I think a tree code should be always prefered to a
 builtin function call - which means a rotate is more canonical than a
 bswap16 call.

 Below is the updated patch. ChangeLog entries are as follows:

 *** gcc/ChangeLog ***

 2014-10-29  Thomas Preud'homme  thomas.preudho...@arm.com

 PR tree-optimization/63259
 * tree-ssa-math-opts.c (bswap_replace): Replace expression by a
 rotation left if it is a 16 bit byte swap.
 (pass_optimize_bswap::execute): Also consider bswap in LROTATE_EXPR 
 and
 RROTATE_EXPR statements if it is a byte rotation.


 *** gcc/testsuite/ChangeLog ***

 2014-10-29  Thomas Preud'homme  thomas.preudho...@arm.com

 PR tree-optimization/63259
 * optimize-bswapsi-1.c (swap32_f): New bswap pass test.
 * optimize-bswaphi-1.c: Drop useless SIType definition and fix typo in
 following comment.


 diff --git a/gcc/testsuite/gcc.dg/optimize-bswaphi-1.c 
 b/gcc/testsuite/gcc.dg/optimize-bswaphi-1.c
 index 18aba28..692fceb 100644
 --- a/gcc/testsuite/gcc.dg/optimize-bswaphi-1.c
 +++ b/gcc/testsuite/gcc.dg/optimize-bswaphi-1.c
 @@ -42,11 +42,10 @@ uint32_t read_be16_3 (unsigned char *data)
return *(data + 1) | (*data  8);
  }

 -typedef int SItype __attribute__ ((mode (SI)));
  typedef int HItype __attribute__ ((mode (HI)));

  /* Test that detection of significant sign extension works correctly. This
 -   checks that unknown byte marker are set correctly in cast of cast.  */
 +   checks that unknown byte markers are set correctly in cast of cast.  */

  HItype
  swap16 (HItype in)
 diff --git a/gcc/testsuite/gcc.dg/optimize-bswapsi-1.c 
 b/gcc/testsuite/gcc.dg/optimize-bswapsi-1.c
 index cfde218..ad3ede4 100644
 --- a/gcc/testsuite/gcc.dg/optimize-bswapsi-1.c
 +++ b/gcc/testsuite/gcc.dg/optimize-bswapsi-1.c
 @@ -78,5 +78,16 @@ swap32_e (SItype in)
  | (((in  24)  0xFF)  0);
  }

 -/* { dg-final { scan-tree-dump-times 32 bit bswap implementation found at 
 5 bswap } } */
 +/* This variant comes from PR63259.  It compiles to a gimple sequence that 
 ends
 +   with a rotation instead of a bitwise OR.  */
 +
 +unsigned
 +swap32_f (unsigned in)
 +{
 +  in = ((in  0xff00ff00)   8) | ((in  0x00ff00ff)   8);
 +  in = ((in  0x)  16) | ((in  0x)  16);
 +  return in;
 +}
 +
 +/* { dg-final { scan-tree-dump-times 32 bit bswap implementation found at 
 6 bswap } } */
  /* { dg-final { cleanup-tree-dump bswap } } */
 diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
 index e0f2924..5b656e0 100644
 --- a/gcc/tree-ssa-math-opts.c
 +++ b/gcc/tree-ssa-math-opts.c
 @@ -2187,7 +2187,7 @@ bswap_replace (gimple cur_stmt, gimple_stmt_iterator 
 gsi, gimple src_stmt,
struct symbolic_number *n, bool bswap)
  {
tree src, tmp, tgt;
 -  gimple call;
 +  gimple bswap_stmt;

src = gimple_assign_rhs1 (src_stmt);
tgt = gimple_assign_lhs (cur_stmt);
 @@ -2293,16 +2293,28 @@ bswap_replace (gimple cur_stmt, gimple_stmt_iterator 
 gsi, gimple src_stmt,

tmp = src;

 -  /* Convert the src expression if necessary.  */
 -  if (!useless_type_conversion_p (TREE_TYPE (tmp), bswap_type))
 +  /* Canonical form for 16 bit bswap is a rotate expression.  */
 +  if (bswap  n-range == 16)
  {
 -  gimple convert_stmt;
 -  tmp = make_temp_ssa_name (bswap_type, NULL, bswapsrc);
 -  convert_stmt = gimple_build_assign_with_ops (NOP_EXPR, tmp, src, NULL);
 -  gsi_insert_before (gsi, convert_stmt, GSI_SAME_STMT);
 +  tree count = build_int_cst (NULL, BITS_PER_UNIT);
 +  bswap_type = TREE_TYPE (src);
 +  src = fold_build2 (LROTATE_EXPR, bswap_type, src, count);
 +  bswap_stmt = gimple_build_assign (NULL, src);
  }
 +  else
 +{
 +  /* Convert the src expression if necessary.  */
 +  if (!useless_type_conversion_p (TREE_TYPE (tmp), bswap_type))
 +   {
 + gimple convert_stmt;
 + tmp = make_temp_ssa_name (bswap_type, NULL, bswapsrc);
 + convert_stmt = gimple_build_assign_with_ops (NOP_EXPR, tmp, src,
 +  NULL);
 + gsi_insert_before (gsi, convert_stmt, GSI_SAME_STMT);
 +   }

 -  call = gimple_build_call (fndecl, 1, tmp);
 +  bswap_stmt = gimple_build_call (fndecl, 1, tmp);
 +}

tmp = tgt;

 @@ -2315,7 +2327,7 @@ bswap_replace (gimple cur_stmt, gimple_stmt_iterator 
 gsi, gimple src_stmt,
gsi_insert_after (gsi, convert_stmt, GSI_SAME_STMT);
  }

 -  gimple_call_set_lhs (call, tmp);
 +  gimple_set_lhs (bswap_stmt, tmp);

if (dump_file)
  {
 @@ -2324,7 +2336,7 @@ bswap_replace (gimple 

Re: [Patchv2 3/4] Control SRA and IPA-SRA by a param rather than MOVE_RATIO

2014-10-31 Thread Richard Biener
On Wed, Oct 29, 2014 at 3:39 PM, James Greenhalgh
james.greenha...@arm.com wrote:
 On Wed, Oct 01, 2014 at 05:38:12PM +0100, James Greenhalgh wrote:
 On Fri, Sep 26, 2014 at 10:11:13AM +0100, Richard Biener wrote:
  On Thu, Sep 25, 2014 at 4:57 PM, James Greenhalgh
  james.greenha...@arm.com wrote:
  Given the special value to note the default for the new --params is
  zero a user cannot disable scalarization that way.
 
  I still somehow dislike that you need a target hook to compute the
  default.  Why doesn't it work to do, in opts.c:default_options_optimization
 
  maybe_set_param_value
(PARAM_SRA_MAX_SCALARIZATION_SIZE_SPEED,
 get_move_ratio (speed_p) * MOVE_MAX_PIECES,
 opts-x_param_values, opts_set-x_param_values);
 
  and override that default in targets option_override hook the same way?

 The problem I am having is getting get_move_ratio right, without breaking
 the modular design.

 default_options_optimization, and the rest of opts.c is going to end up in
 libcommon-target.a, so we are not going to have access to any
 backend-specific symbols.

 An early draft of this patch used the MOVE_RATIO macro to set the default
 value. This worked fine for AArch64 and ARM targets (which both use a
 simple C expression for MOVE_RATIO), but failed for x86_64 which defines
 MOVE_RATIO as so:

   #define MOVE_RATIO(speed) ((speed) ? ix86_cost-move_ratio : 3)

 Dealing with that ix86_cost symbol is what causes us the pain.

 It seems reasonable that a target might want to define MOVE_RATIO
 as some function of their tuning parameters, so I don't want to
 disallow that usage.

 This inspired me to try turning this in to a target hook, but this
 doesn't help as opts.c only gets access to common-target.def target
 hooks. These suffer the same problem, they don't have access to any
 backend symbols.

 I suppose I could port any target with a definition of MOVE_RATIO to
 override the default parameter value in their option overriding code,
 but that makes this a very large patch set (many targets define
 MOVE_RATIO).

 Is this an avenue worth exploring? I agree the very special target
 hook is not ideal.

 Hi,

 Did you have any further thoughts on this? I'm still unable to come up
 with a way to set these parameters which allows them to default to their
 current (MOVE_RATIO derived) values.

 If the only way to make this work is to add code to
 TARGET_OPTION_OVERRIDE for all targets that define MOVE_RATIO, then I
 suppose I can do that, but I'd prefer a neater way to make it work, if
 you can think of one.

Maybe instead of putting the code in opts.c put it right before we call
targetm.target_option.override () in toplev.c:process_options.  With
a comment on why it cannot be in opts.c.

Thanks,
Richard.

 Thanks,
 James



Re: [Patch] Cleanup widest_int_mode_for_size

2014-10-31 Thread Richard Biener
On Tue, Sep 23, 2014 at 11:17 AM, James Greenhalgh
james.greenha...@arm.com wrote:

 Hi,

 The comment on widest_int_mode_for_size claims that it returns the
 widest integer mode no wider than size. The implementation looks more
 like it finds the widest integer mode smaller than size. Everywhere it
 is used, the mode it is looking for is ultimately checked against an
 expected alignment or is used for heuristics that should be thinking
 about that check, so pull it in to here.

 Throughout expr.c corrections are made for this fact - adding one to
 the size passed to this function. This feels a bit backwards to me.

 This patch fixes that, and then fixes the fallout throughout expr.c.
 Generally, this means simplifying a bunch of move_by_pieces style copy
 code.

 Bootstrapped on x86_64, arm and AArch64 with no issues.

I suppose you verified the generated code is the same?

Btw, this all looks more like this wants to be an iterator-style approach,
iterating over modes from larger to narrower that honor the alignment.

Repeatedly iterating over all modes in the loops iterating towards
smaller modes looks backward.  Iterating by asking for size - 1
in the next round isn't much clearer than asking for size + 1 either.

 OK for trunk?

So I'm not sure this is a real improvement.  Instead changing the loops
to explicitely iterate via GET_MODE_NARROWER_MODE (oops - we don't
have that, but it should be easy to add) would be better.

Thanks,
Richard.

 Thanks,
 James

 2014-09-23  James Greenhalgh  james.greenha...@arm.com

 * expr.c (MOVE_BY_PIECES_P): Remove off-by-one correction to
 move_by_pieces_ninsns.
 (CLEAR_BY_PIECES_P): Likewise.
 (SET_BY_PIECES_P): Likewise.
 (STORE_BY_PIECES_P): Likwise.
 (widest_int_mode_for_size): Return the widest mode in which the
 given size fits.
 (move_by_pieces): Remove off-by-one correction for max_size,
 simplify copy loop body.
 (move_by_pieces_ninsns): Simplify copy body.
 (can_store_by_pieces): Remove off-by-one correction for max_size,
 simplify copy body.
 (store_by_pieces_1): Likewise.


[PATCH] Fix VRP of UBSAN_SUB_CHECK (PR sanitizer/63697)

2014-10-31 Thread Jakub Jelinek
Hi!

This patch fixes a thinko in VRP of UBSAN_SUB_CHECK -
if we have two VR_RANGEs for subtraction, to detect whether
the subtraction might overflow we need to check if
op0's minimum - op1's maximum overflow or if
op0's maximum - op1's minimum overflow, while the code
has been checking both maximums and minimums together instead
(like is needed for UBSAN_ADD_CHECK; for UBSAN_MUL_CHECK
we were testing all 4 combinations, so it should be fine).

The attached testcase shows that this bug caused us to miss
reporting one of the overflows.

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

2014-10-31  Jakub Jelinek  ja...@redhat.com

PR sanitizer/63697
* tree-vrp.c (simplify_internal_call_using_ranges): For subcode ==
MINUS_EXPR, check overflow on vr0.min - vr1.max and vr0.max - vr1.min
instead of vr0.min - vr1.min and vr0.max - vr1.max.

* c-c++-common/ubsan/overflow-sub-3.c: New test.

--- gcc/tree-vrp.c.jj   2014-10-30 14:42:19.0 +0100
+++ gcc/tree-vrp.c  2014-10-31 09:49:52.323772046 +0100
@@ -9538,8 +9538,10 @@ simplify_internal_call_using_ranges (gim
 }
   else
 {
-  tree r1 = int_const_binop (subcode, vr0.min, vr1.min);
-  tree r2 = int_const_binop (subcode, vr0.max, vr1.max);
+  tree r1 = int_const_binop (subcode, vr0.min,
+subcode == MINUS_EXPR ? vr1.max : vr1.min);
+  tree r2 = int_const_binop (subcode, vr0.max,
+subcode == MINUS_EXPR ? vr1.min : vr1.max);
   if (r1 == NULL_TREE || TREE_OVERFLOW (r1)
  || r2 == NULL_TREE || TREE_OVERFLOW (r2))
return false;
--- gcc/testsuite/c-c++-common/ubsan/overflow-sub-3.c.jj2014-10-31 
09:54:17.279910346 +0100
+++ gcc/testsuite/c-c++-common/ubsan/overflow-sub-3.c   2014-10-31 
09:54:13.194083245 +0100
@@ -0,0 +1,34 @@
+/* { dg-do run } */
+/* { dg-options -fsanitize=signed-integer-overflow } */
+
+__attribute__((noinline, noclone)) int
+foo1 (int x, int y)
+{
+  return x - y;
+}
+
+__attribute__((noinline, noclone)) int
+foo2 (int x, int y)
+{
+  unsigned int xa = (unsigned int) x - (__INT_MAX__ - 3);
+  xa = 3;
+  x = __INT_MAX__ - 3 + xa;
+  unsigned int ya = y + 1U;
+  ya = 1;
+  y = ya - 1;
+  return x - y;
+}
+
+int
+main ()
+{
+  int xm1, y;
+  for (xm1 = __INT_MAX__ - 4; xm1  __INT_MAX__; xm1++)
+for (y = -1; y = 0; y++)
+  if (foo1 (xm1 + 1, y) != (int) (xm1 + 1U - y)
+ || foo2 (xm1 + 1, y) != (int) (xm1 + 1U - y))
+   __builtin_abort ();
+  return 0;
+}
+/* { dg-output :7:\[0-9]\[^\n\r]*signed integer overflow: 2147483647 - -1 
cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r) } */
+/* { dg-output \[^\n\r]*:19:\[0-9]\[^\n\r]*signed integer overflow: 
2147483647 - -1 cannot be represented in type 'int' } */

Jakub


[Ada] Tag initialization in object declarations

2014-10-31 Thread Arnaud Charlet
When a tagged object is initialized in a declaration, the expression may
involve a view conversion, so the tag must be re-assigned explicitly to the
object in a separate step. This assignment can only take place after the
object is frozen.  If there is an address clause for the object following
the declaration, the tag assignment must appear as part of the freeze qctions
for the object, and these actions must be properly analyzed.
The following must compile quietly:

---
with System;
package body P is
   procedure Dummy is begin null; end;

   procedure Proc (Value : T;
   Value_Address : System.Address;
   Value_Access  : out T_Access) is
  Local : aliased T := Value;
  for Local'Address use Value_Address;
   begin
  Value_Access := Local'Unchecked_Access;
   end;
end P;
---
package P is
   type T is tagged null record;

   type T_Access is access all T;

   procedure Dummy;
end P;

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Ed Schonberg  schonb...@adacore.com

* exp_ch3.ads (Make_Tag_Assignment): New function, used to
re-initialize the tag in a tagged object declaration with
initial value.
* exp_ch3.adb (Expand_N_Object_Declaration): Use
Make_Tag_Assignment to simplify code for a tagged object
declaration.
* exp_ch13.adb (Expand_Freeze_Entity): Analyze freeze actions
for the freeze node of an object.
* freeze.adb (Check_Address_Clause): Use Make_Tag_Assignment when
needed to extend Freeze_Actions for a tagged object declaration.

Index: freeze.adb
===
--- freeze.adb  (revision 216925)
+++ freeze.adb  (working copy)
@@ -578,11 +578,13 @@
--
 
procedure Check_Address_Clause (E : Entity_Id) is
-  Addr : constant Node_Id:= Address_Clause (E);
-  Expr : Node_Id;
-  Decl : constant Node_Id:= Declaration_Node (E);
-  Loc  : constant Source_Ptr := Sloc (Decl);
-  Typ  : constant Entity_Id  := Etype (E);
+  Addr   : constant Node_Id:= Address_Clause (E);
+  Expr   : Node_Id;
+  Decl   : constant Node_Id:= Declaration_Node (E);
+  Loc: constant Source_Ptr := Sloc (Decl);
+  Typ: constant Entity_Id  := Etype (E);
+  Lhs: Node_Id;
+  Tag_Assign : Node_Id;
 
begin
   if Present (Addr) then
@@ -636,9 +638,13 @@
 
  if Present (Expression (Decl)) then
 
---  Capture initialization value at point of declaration
+--  Capture initialization value at point of declaration,
+--  and make explicit assignment legal, because object may
+--  be a constant.
 
 Remove_Side_Effects (Expression (Decl));
+Lhs := New_Occurrence_Of (E, Loc);
+Set_Assignment_OK (Lhs);
 
 --  Move initialization to freeze actions (once the object has
 --  been frozen, and the address clause alignment check has been
@@ -646,10 +652,19 @@
 
 Append_Freeze_Action (E,
   Make_Assignment_Statement (Loc,
-Name   = New_Occurrence_Of (E, Loc),
+Name   = Lhs,
 Expression = Expression (Decl)));
 
 Set_No_Initialization (Decl);
+
+--  If the objet is tagged, check whether the tag must be
+--  reassigned expliitly.
+
+Tag_Assign := Make_Tag_Assignment (Decl);
+if Present (Tag_Assign) then
+   Append_Freeze_Action (E, Tag_Assign);
+end if;
+
  end if;
   end if;
end Check_Address_Clause;
Index: exp_ch13.adb
===
--- exp_ch13.adb(revision 216925)
+++ exp_ch13.adb(working copy)
@@ -418,6 +418,20 @@
 Apply_Address_Clause_Check (E, N);
  end if;
 
+ --  Analyze actions in freeze node, if any.
+
+ if Present (Actions (N)) then
+declare
+   Act : Node_Id;
+begin
+   Act := First (Actions (N));
+   while Present (Act) loop
+  Analyze (Act);
+  Next (Act);
+   end loop;
+end;
+ end if;
+
  --  If initialization statements have been captured in a compound
  --  statement, insert them back into the tree now.
 
@@ -566,7 +580,7 @@
   --  If subprogram, freeze the subprogram
 
   elsif Is_Subprogram (E) then
- Freeze_Subprogram (N);
+ Exp_Ch6.Freeze_Subprogram (N);
 
  --  Ada 2005 (AI-251): Remove the freezing node associated with the
  --  entities internally used by the frontend to register primitives
Index: exp_ch3.adb
===
--- exp_ch3.adb (revision 216926)
+++ exp_ch3.adb (working 

[PATCH] Don't bootstrap libcc1

2014-10-31 Thread Jakub Jelinek
On Thu, Oct 30, 2014 at 09:39:06AM +0100, Paolo Bonzini wrote:
  --- configure.ac   2014-10-28 14:39:53.018852391 +0100
  +++ configure.ac   2014-10-29 11:43:19.873216226 +0100
  @@ -2677,6 +2677,7 @@ for module in ${configdirs} ; do
 fi
 case ${module},${bootstrap_fixincludes} in
   fixincludes,no) host_bootstrap_suffix=no-bootstrap ;;
  +libcc1,*) host_bootstrap_suffix=no-bootstrap ;;
   *) host_bootstrap_suffix=$bootstrap_suffix ;;
 esac
 extrasub_host=$extrasub_host
  
  Makefile.def has:
  host_modules= { module= libcc1; bootstrap=true;
  extra_configure_flags=--enable-shared; };
  wonder if that bootstrap=true; is desirable there.
 
 No, it shouldn't be there

Seems removing that makes the configure.ac change unneeded.
Bootstrapped/regtested on x86_64-linux and i686-linux (libcc1
is built after compare, by stage3 compiler), and built
with --disable-bootstrap on i686-linux (libcc1 is built by
the system compiler in that case).  Ok for trunk?

2014-10-31  Jakub Jelinek  ja...@redhat.com

* Makefile.def (libcc1): Remove bootstrap=true;.
* Makefile.in: Regenerated.

--- Makefile.def.jj 2014-10-28 14:40:30.0 +0100
+++ Makefile.def2014-10-31 10:10:22.723173845 +0100
@@ -123,8 +123,7 @@ host_modules= { module= gnattools; };
 host_modules= { module= lto-plugin; bootstrap=true;
extra_configure_flags='--enable-shared 
@extra_linker_plugin_flags@ @extra_linker_plugin_configure_flags@';
extra_make_flags='@extra_linker_plugin_flags@'; };
-host_modules= { module= libcc1; bootstrap=true;
-   extra_configure_flags=--enable-shared; };
+host_modules= { module= libcc1; extra_configure_flags=--enable-shared; };
 
 target_modules = { module= libstdc++-v3;
   bootstrap=true;
--- Makefile.in.jj  2014-10-28 14:39:52.0 +0100
+++ Makefile.in 2014-10-31 10:10:51.0 +0100
@@ -1085,9 +1085,7 @@ all-host: maybe-all-gnattools
 @if lto-plugin-no-bootstrap
 all-host: maybe-all-lto-plugin
 @endif lto-plugin-no-bootstrap
-@if libcc1-no-bootstrap
 all-host: maybe-all-libcc1
-@endif libcc1-no-bootstrap
 
 .PHONY: all-target
 
@@ -32264,6 +32262,7 @@ configure-libcc1: stage_current
 @if libcc1
 maybe-configure-libcc1: configure-libcc1
 configure-libcc1: 
+   @: $(MAKE); $(unstage)
@r=`${PWD_COMMAND}`; export r; \
s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
test ! -f $(HOST_SUBDIR)/libcc1/Makefile || exit 0; \
@@ -32287,211 +32286,6 @@ configure-libcc1:
 
 
 
-.PHONY: configure-stage1-libcc1 maybe-configure-stage1-libcc1
-maybe-configure-stage1-libcc1:
-@if libcc1-bootstrap
-maybe-configure-stage1-libcc1: configure-stage1-libcc1
-configure-stage1-libcc1:
-   @[ $(current_stage) = stage1 ] || $(MAKE) stage1-start
-   @$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/libcc1
-   @r=`${PWD_COMMAND}`; export r; \
-   s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
-   TFLAGS=$(STAGE1_TFLAGS); \
-   test ! -f $(HOST_SUBDIR)/libcc1/Makefile || exit 0; \
-   $(HOST_EXPORTS) \
-   CFLAGS=$(STAGE1_CFLAGS); export CFLAGS; \
-   CXXFLAGS=$(STAGE1_CXXFLAGS); export CXXFLAGS; \
-   LIBCFLAGS=$(LIBCFLAGS); export LIBCFLAGS;  \
-   echo Configuring stage 1 in $(HOST_SUBDIR)/libcc1 ; \
-   $(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/libcc1 ; \
-   cd $(HOST_SUBDIR)/libcc1 || exit 1; \
-   case $(srcdir) in \
- /* | [A-Za-z]:[\\/]*) topdir=$(srcdir) ;; \
- *) topdir=`echo $(HOST_SUBDIR)/libcc1/ | \
-   sed -e 's,\./,,g' -e 's,[^/]*/,../,g' `$(srcdir) ;; \
-   esac; \
-   module_srcdir=libcc1; \
-   $(SHELL) $$s/$$module_srcdir/configure \
- --srcdir=$${topdir}/$$module_srcdir \
- $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
- --target=${target_alias} \
-  \
- $(STAGE1_CONFIGURE_FLAGS) \
- --enable-shared
-@endif libcc1-bootstrap
-
-.PHONY: configure-stage2-libcc1 maybe-configure-stage2-libcc1
-maybe-configure-stage2-libcc1:
-@if libcc1-bootstrap
-maybe-configure-stage2-libcc1: configure-stage2-libcc1
-configure-stage2-libcc1:
-   @[ $(current_stage) = stage2 ] || $(MAKE) stage2-start
-   @$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/libcc1
-   @r=`${PWD_COMMAND}`; export r; \
-   s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
-   TFLAGS=$(STAGE2_TFLAGS); \
-   test ! -f $(HOST_SUBDIR)/libcc1/Makefile || exit 0; \
-   $(HOST_EXPORTS) \
-   $(POSTSTAGE1_HOST_EXPORTS) \
-   CFLAGS=$(STAGE2_CFLAGS); export CFLAGS; \
-   CXXFLAGS=$(STAGE2_CXXFLAGS); export CXXFLAGS; \
-   LIBCFLAGS=$(STAGE2_CFLAGS); export LIBCFLAGS;  \
-   echo Configuring stage 2 in $(HOST_SUBDIR)/libcc1 ; \
-   $(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/libcc1 ; \
-   cd $(HOST_SUBDIR)/libcc1 || exit 1; \
-   case $(srcdir) in \
- /* | [A-Za-z]:[\\/]*) topdir=$(srcdir) 

[Ada] Handling of implicit dereference in instantiations

2014-10-31 Thread Arnaud Charlet
The use of reference types and generalized indexing leads to multiple tree
rewritings. When these uses are in a generic unit, the transformations are not
propagated to instantiations, and the analysis of the instance must replicate
that of the generic to recognize the presence of implicit dereferences. This
patch removes some global information from selected components whose prefix
involves an implicit dereference, to force the re-analysis and resolution in
the instantiation.

Executing;

   gnatmake -q cont
   cont

must yield:

   1234
   1234
   1234
   2468

---
with Par; use Par;
with Par.Child;
with Ada.Finalization; use Ada.Finalization;
procedure Cont is
   use My_Lists;
   Bunch : List;
   Ptr   : Cursor;
   package Inst is new Par.Child;
   use Inst;
begin
   Append (Bunch, R'(Controlled with Kind = 1234));
   Try (Bunch, Bunch.First);
end;
---
with ada.containers.doubly_linked_lists;
with Ada.Finalization; use Ada.Finalization;
use ada.containers;
package Par is
 type R is new Ada.Finalization.Controlled with record
  Kind : Integer;
   end record;

   package My_Lists is new Doubly_Linked_Lists (R);
end Par;
---
generic
package Par.Child is
   use My_Lists;
   procedure Try (Bunch: List; C : Cursor);
end Par.Child;
--
with Text_IO; use Text_IO;
package body Par.Child is
   use My_Lists;
   procedure Try (Bunch: List; C : Cursor) is
  V1 : Integer := Constant_Reference (Bunch, C).Element.Kind;
  V2 : Integer := Constant_Reference (Bunch, C).Kind;
  V3 : Integer := Bunch (C).Kind;
   begin
  Put_Line (Integer'Image (V1));
  Put_Line (Integer'Image (V2));
  Put_Line (Integer'Image (V3));

  for Elmt of Bunch loop
 Put_Line (Integer'Image (2 * Elmt.Kind));
  end loop;
   end;
end Par.Child;

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Ed Schonberg  schonb...@adacore.com

* sem_ch4.adb (Try_Container_Indexing): Use Check_Implicit_Dereference.
* sem_util.adb (Check_Implicit_Dereference): a) Handle generalized
indexing as well as function calls.  b)  If the context is a
selected component and whe are in an instance, remove entity from
selector name to force resolution of the node, so that explicit
dereferences can be generated in the instance if they were in
the generic unit.

Index: sem_util.adb
===
--- sem_util.adb(revision 216925)
+++ sem_util.adb(working copy)
@@ -2673,17 +2673,29 @@
-- Check_Implicit_Dereference --

 
-   procedure Check_Implicit_Dereference (Nam : Node_Id;  Typ : Entity_Id) is
+   procedure Check_Implicit_Dereference (N : Node_Id;  Typ : Entity_Id) is
   Disc  : Entity_Id;
   Desig : Entity_Id;
+  Nam   : Node_Id;
 
begin
+  if Nkind (N) = N_Indexed_Component
+and then Present (Generalized_Indexing (N))
+  then
+ Nam := Generalized_Indexing (N);
+
+  else
+ Nam := N;
+  end if;
+
   if Ada_Version  Ada_2012
 or else not Has_Implicit_Dereference (Base_Type (Typ))
   then
  return;
 
-  elsif not Comes_From_Source (Nam) then
+  elsif not Comes_From_Source (N)
+and then Nkind (N) /= N_Indexed_Component
+  then
  return;
 
   elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
@@ -2695,6 +2707,26 @@
 if Has_Implicit_Dereference (Disc) then
Desig := Designated_Type (Etype (Disc));
Add_One_Interp (Nam, Disc, Desig);
+
+   --  If the node is a generalized indexing, add interpretation
+   --  to that node as well, for subsequent resolution.
+
+   if Nkind (N) = N_Indexed_Component then
+  Add_One_Interp (N, Disc, Desig);
+   end if;
+
+   --  If the operation comes from a generic unit and the context
+   --  is a selected component, the selector name may be global
+   --  and set in the instance already. Remove the entity to
+   --  force resolution of the selected component, and the
+   --  generation of an explicit dereference if needed.
+
+   if In_Instance
+ and then Nkind (Parent (Nam)) = N_Selected_Component
+   then
+  Set_Entity (Selector_Name (Parent (Nam)), Empty);
+   end if;
+
exit;
 end if;
 
@@ -16543,11 +16575,21 @@
begin
   --  Nothing to do if argument is Empty or has Debug_Info_Off set, which
   --  indicates that Debug_Info_Needed is never required for the entity.
+  --  Nothing to do if entity comes from a predefined file. Library files
+  --  are compiled without debug information, but inlined bodies of these
+  --  routines may appear in user code, and debug information on them ends
+  --  up complicating debugging the 

[Ada] Lift obsolete limitations for pragma Inline

2014-10-31 Thread Arnaud Charlet
This change lifts obsolete limitations for pragma Inline that have already
been lifted for pragma Inline_Always, since they use the same machinery.

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Eric Botcazou  ebotca...@adacore.com

* inline.adb (Back_End_Cannot_Inline): Delete.
(Add_Inlined_Subprogram): Do not call it.

Index: inline.adb
===
--- inline.adb  (revision 216925)
+++ inline.adb  (working copy)
@@ -445,20 +445,6 @@
   E: constant Entity_Id := Inlined.Table (Index).Name;
   Pack : constant Entity_Id := Get_Code_Unit_Entity (E);
 
-  function Back_End_Cannot_Inline (Subp : Entity_Id) return Boolean;
-  --  There are various conditions under which back-end inlining cannot
-  --  be done reliably:
-  --
-  --a) If a body has handlers, it must not be inlined, because this
-  --may violate program semantics, and because in zero-cost exception
-  --mode it will lead to undefined symbols at link time.
-  --
-  --b) If a body contains inlined function instances, it cannot be
-  --inlined under ZCX because the numeric suffix generated by gigi
-  --will be different in the body and the place of the inlined call.
-  --
-  --  This procedure must be carefully coordinated with the back end.
-
   procedure Register_Backend_Inlined_Subprogram (Subp : Entity_Id);
   --  Append Subp to the list of subprograms inlined by the backend
 
@@ -466,52 +452,6 @@
   --  Append Subp to the list of subprograms that cannot be inlined by
   --  the backend.
 
-  
-  -- Back_End_Cannot_Inline --
-  
-
-  function Back_End_Cannot_Inline (Subp : Entity_Id) return Boolean is
- Decl : constant Node_Id := Unit_Declaration_Node (Subp);
- Body_Ent : Entity_Id;
- Ent  : Entity_Id;
-
-  begin
- if Nkind (Decl) = N_Subprogram_Declaration
-   and then Present (Corresponding_Body (Decl))
- then
-Body_Ent := Corresponding_Body (Decl);
- else
-return False;
- end if;
-
- --  If subprogram is marked Inline_Always, inlining is mandatory
-
- if Has_Pragma_Inline_Always (Subp) then
-return False;
- end if;
-
- if Present
-  (Exception_Handlers
- (Handled_Statement_Sequence
-(Unit_Declaration_Node (Corresponding_Body (Decl)
- then
-return True;
- end if;
-
- Ent := First_Entity (Body_Ent);
- while Present (Ent) loop
-if Is_Subprogram (Ent)
-  and then Is_Generic_Instance (Ent)
-then
-   return True;
-end if;
-
-Next_Entity (Ent);
- end loop;
-
- return False;
-  end Back_End_Cannot_Inline;
-
   -
   -- Register_Backend_Inlined_Subprogram --
   -
@@ -547,21 +487,15 @@
 and then not Is_Nested (E)
 and then not Has_Initialized_Type (E)
   then
- if Back_End_Cannot_Inline (E) then
-Set_Is_Inlined (E, False);
-Register_Backend_Not_Inlined_Subprogram (E);
+ Register_Backend_Inlined_Subprogram (E);
 
+ if No (Last_Inlined) then
+Set_First_Inlined_Subprogram (Cunit (Main_Unit), E);
  else
-Register_Backend_Inlined_Subprogram (E);
-
-if No (Last_Inlined) then
-   Set_First_Inlined_Subprogram (Cunit (Main_Unit), E);
-else
-   Set_Next_Inlined_Subprogram (Last_Inlined, E);
-end if;
-
-Last_Inlined := E;
+Set_Next_Inlined_Subprogram (Last_Inlined, E);
  end if;
+
+ Last_Inlined := E;
   else
  Register_Backend_Not_Inlined_Subprogram (E);
   end if;


Re: [PATCH] config-list.mk: Build Go only for supported targets (was: Patch RFA: Top-level configure patch: disable go on systems where it doesn't work)

2014-10-31 Thread Jan-Benedict Glaw
On Thu, 2014-10-30 17:10:38 -0700, Ian Taylor i...@golang.org wrote:
 On Thu, Oct 30, 2014 at 12:14 PM, Jan-Benedict Glaw jbg...@lug-owl.de wrote:
  On Thu, 2014-10-30 08:08:51 -0700, Ian Taylor i...@golang.org wrote:
   On Thu, Oct 30, 2014 at 6:19 AM, Jan-Benedict Glaw jbg...@lug-owl.de 
   wrote:
This updates contrib/config-list.mk to build Go for all but
known-non-working targets. A comment to configure{.ac,} is
also added.
[Fiddling with target names]
  Not exactly: My intention was to keep the triplet matches as they
  show up in configure.ac .  However, the target list in
  config-list.mk uses (almost exclusively) shorthands for all the
  targets, so these need to be expand (-- config.sub); that however
  won't really fly with the OPTs in there.
 
 Oh, right, sorry.
 
 The original patch is OK.

Thanks, committed as r216957.

MfG, JBG

-- 
  Jan-Benedict Glaw  jbg...@lug-owl.de  +49-172-7608481
Signature of:  What we do for ourselves dies with us. What we do for
the second  : others and the world remains and is immortal. (Albert 
Pine)


signature.asc
Description: Digital signature


RE: [PATCH, ifcvt] Check size cost in noce_try_store_flag_mask

2014-10-31 Thread Matthew Fortune
Andrew Pinski pins...@gmail.com writes:
 On Thu, Oct 30, 2014 at 11:30 PM, Zhenqiang Chen zhenqiang.c...@arm.com
 wrote:
  Thank you all for the comments. Patch is updated.
 
  Bootstrap and no make check regression on X86-64.
  No make check regression with Cortex-M0 qemu.
  No performance changes for coremark, dhrystone, spec2000 and spec2006 on
  X86-64 and Cortex-A15.
 
  For CSiBE, ARM Cortex-M0 result is a little better. A little regression
 for
  MIPS (less than 0.01%).
 
 I think I have a fix for MIPS which I need to submit too.  The problem
 is IF_THEN_ELSE is not implemented for mips_rtx_costs.
 
 Something like the attached one (though It is not updated for the new
 cores including octeon3).

This looks OK in principle so I have no objection to the original patch
from Zhengiang. The MIPS patch can follow on.

Andrew: Are you setting higher costs for octeon to try and avoid the
conversion owing to high latency for MOV[NZ] etc in octeon*? Should that
be conditional on speed vs size?

Thanks,
Matthew


[Ada] Calls to protected operations in pre/postcondition

2014-10-31 Thread Arnaud Charlet
A protected specification cannot contain calls to its own operations, except
if the call appears within a pre- or postcondition for another protected
operation.

Executing:

   gnatmake -q -gnata prot
   prot

must yield:

   Good call
   Bad call


---
with Text_IO; use Text_IO;
with Ada.Assertions;  use Ada.Assertions;
procedure Prot is

   protected T is
  procedure Set;
  function Is_Empty return Boolean; --   is (True);

  procedure Pop (V : out Integer)
 with Pre = not Is_Empty, Post = V  10;

   private
  Empty : Boolean := True;
   end T;

   protected body T is
  procedure Set is
  begin
 Empty := False;
  end;

  function Is_Empty return Boolean is
  begin
 return Empty;
  end Is_Empty;

  procedure Pop (V : out Integer) is
  begin
 V := 20;
 Empty := True;
  end Pop;

   end T;
   Counter : Integer := 0;
begin
   T.Set;
   T.Pop (Counter);
   Put_Line (Good call);

   begin
  T.Pop (Counter);
   exception
  when Assertion_Error = Put_Line (Bad call);
   end;
end Prot;

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Ed Schonberg  schonb...@adacore.com

* sem_res.adb (Resolve_Call): Do not reject a call to a protected
operation in the spec of a protected type, when the call appears
in a pre/postcondition for another protected operation.

Index: sem_res.adb
===
--- sem_res.adb (revision 216925)
+++ sem_res.adb (working copy)
@@ -6022,11 +6022,13 @@
   end if;
 
   --  A protected function cannot be called within the definition of the
-  --  enclosing protected type.
+  --  enclosing protected type, unless it is part of a pre/postcondition
+  --  on another protected operation.
 
   if Is_Protected_Type (Scope (Nam))
 and then In_Open_Scopes (Scope (Nam))
 and then not Has_Completion (Scope (Nam))
+and then not In_Spec_Expression
   then
  Error_Msg_NE
( cannot be called before end of protected definition, N, Nam);


Re: update address taken: don't drop clobbers

2014-10-31 Thread Richard Biener
On Sat, Oct 25, 2014 at 6:29 PM, Marc Glisse marc.gli...@inria.fr wrote:
 On Fri, 24 Oct 2014, Jeff Law wrote:

 I'm starting to agree -- a later message indicated you wanted to drop the
 unlink_stmt_vdef call and you wanted to avoid gsi_replace, that seems fine.
 I'll approve once those things are taken care of.


 The following passed bootstrap+testsuite. I wasn't sure what exactly a
 clobber is guaranteed not to have (no histograms for instance? At least I
 assumed it doesn't throw) so I may have kept some unnecessary calls when I
 inlined gsi_replace. I'd be happy to remove any you feel is useless.

 2014-10-26  Marc Glisse  marc.gli...@inria.fr

 PR tree-optimization/60770
 gcc/
 * tree-into-ssa.c: Include value-prof.h.
 (maybe_register_def): Replace clobbers with default definitions.
 * tree-ssa-live.c: Include tree-ssa.h.
 (set_var_live_on_entry): Do not mark undefined variables as live.
 (verify_live_on_entry): Do not check undefined variables.
 * tree-ssa.h (ssa_undefined_value_p): New parameter for the case
 of partially undefined variables.
 * tree-ssa.c (ssa_undefined_value_p): Likewise.
 (execute_update_addresses_taken): Do not drop clobbers.

 gcc/testsuite/
 * gcc.dg/tree-ssa/pr60770-1.c: New file.

 --
 Marc Glisse

 Index: gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c
 ===
 --- gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c   (revision 0)
 +++ gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c   (working copy)
 @@ -0,0 +1,11 @@
 +/* { dg-do compile } */
 +/* { dg-options -O -Wall } */
 +
 +int f(int n){
 +  int*p;
 +  {
 +int yyy=n;
 +p=yyy;
 +  }
 +  return *p; /* { dg-warning yyy } */
 +}
 Index: gcc/tree-into-ssa.c
 ===
 --- gcc/tree-into-ssa.c (revision 216689)
 +++ gcc/tree-into-ssa.c (working copy)
 @@ -52,20 +52,21 @@ along with GCC; see the file COPYING3.
  #include expr.h
  #include tree-dfa.h
  #include tree-ssa.h
  #include tree-inline.h
  #include tree-pass.h
  #include cfgloop.h
  #include domwalk.h
  #include params.h
  #include diagnostic-core.h
  #include tree-into-ssa.h
 +#include value-prof.h

  #define PERCENT(x,y) ((float)(x) * 100.0 / (float)(y))

  /* This file builds the SSA form for a function as described in:
 R. Cytron, J. Ferrante, B. Rosen, M. Wegman, and K. Zadeck. Efficiently
 Computing Static Single Assignment Form and the Control Dependence
 Graph. ACM Transactions on Programming Languages and Systems,
 13(4):451-490, October 1991.  */

  /* Structure to map a variable VAR to the set of blocks that contain
 @@ -1837,26 +1838,42 @@ maybe_register_def (def_operand_p def_p,
  {
tree def = DEF_FROM_PTR (def_p);
tree sym = DECL_P (def) ? def : SSA_NAME_VAR (def);

/* If DEF is a naked symbol that needs renaming, create a new
   name for it.  */
if (marked_for_renaming (sym))
  {
if (DECL_P (def))
 {
 - tree tracked_var;
 + if (gimple_clobber_p (stmt)  is_gimple_reg (sym))

I think you know that sym is a gimple-reg as the code previously
unconditionally generated an SSA name for it.

 +   {
 + /* Replace clobber stmts with a default def. This new use of a
 +default definition may make it look like SSA_NAMEs have
 +conflicting lifetimes, so we need special code to let them
 +coalesce properly.  */
 + /* Hand-inlined version of the following, for safety
 +gsi_replace (gsi, gimple_build_nop (), true);  */
 + gimple nop = gimple_build_nop ();
 + gimple_set_bb (nop, gsi_bb (gsi));
 + gimple_set_bb (stmt, NULL);
 + gimple_remove_stmt_histograms (cfun, stmt);
 + delink_stmt_imm_use (stmt);
 + gsi_set_stmt (gsi, nop);

Is there any reason for this dance?  I'd rather have maybe_register_def
return a bool whether to remove the stmt... passing it down to the
single caller of rewrite_update_stmt which can then gsi_remove the
stmt.

 - def = make_ssa_name (def, stmt);
 + def = get_or_create_ssa_default_def (cfun, sym);

I think if 'def' turns out to be a PARM_DECL this does the wrong
thing (well, not technically wrong...  but maybe unexpected).  Not
sure if we ever end up with a PARM = {} clobber though.  Maybe
guard all this with TREE_CODE (def) == VAR_DECL for extra
safety.

Otherwise the patch looks ok.

Thanks for your patience.
Richard.

 +   }
 + else
 +   def = make_ssa_name (def, stmt);
   SET_DEF (def_p, def);

 - tracked_var = target_for_debug_bind (sym);
 + tree tracked_var = target_for_debug_bind (sym);
   if (tracked_var)
 {
   gimple note = gimple_build_debug_bind (tracked_var, def,
 stmt);
   /* If stmt ends the 

[Ada] Aspect Default_Storage_Pool

2014-10-31 Thread Arnaud Charlet
This aspect was not properly recognized by GNAT, even though the corresponding
pragma was fully handled.

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Ed Schonberg  schonb...@adacore.com

* aspects.ads, aspects.adb: Add aspect Default_Storage_Pool.
* sem_ch13.adb (Analyze_One_Aspect): Generate pragma for aspect
Default_Storage_Pool.

Index: aspects.adb
===
--- aspects.adb (revision 216925)
+++ aspects.adb (working copy)
@@ -511,6 +511,7 @@
 Aspect_Default_Component_Value  = Aspect_Default_Component_Value,
 Aspect_Default_Initial_Condition= Aspect_Default_Initial_Condition,
 Aspect_Default_Iterator = Aspect_Default_Iterator,
+Aspect_Default_Storage_Pool = Aspect_Default_Storage_Pool,
 Aspect_Default_Value= Aspect_Default_Value,
 Aspect_Depends  = Aspect_Depends,
 Aspect_Dimension= Aspect_Dimension,
Index: aspects.ads
===
--- aspects.ads (revision 216925)
+++ aspects.ads (working copy)
@@ -88,6 +88,7 @@
   Aspect_Default_Component_Value,
   Aspect_Default_Initial_Condition, -- GNAT
   Aspect_Default_Iterator,
+  Aspect_Default_Storage_Pool,
   Aspect_Default_Value,
   Aspect_Depends,   -- GNAT
   Aspect_Dimension, -- GNAT
@@ -314,6 +315,7 @@
   Aspect_Default_Component_Value   = Expression,
   Aspect_Default_Initial_Condition = Optional_Expression,
   Aspect_Default_Iterator  = Name,
+  Aspect_Default_Storage_Pool  = Expression,
   Aspect_Default_Value = Expression,
   Aspect_Depends   = Expression,
   Aspect_Dimension = Expression,
@@ -401,6 +403,7 @@
   Aspect_Default_Component_Value  = Name_Default_Component_Value,
   Aspect_Default_Initial_Condition= Name_Default_Initial_Condition,
   Aspect_Default_Iterator = Name_Default_Iterator,
+  Aspect_Default_Storage_Pool = Name_Default_Storage_Pool,
   Aspect_Default_Value= Name_Default_Value,
   Aspect_Depends  = Name_Depends,
   Aspect_Dimension= Name_Dimension,
@@ -616,6 +619,7 @@
   Aspect_Constant_Indexing= Always_Delay,
   Aspect_CPU  = Always_Delay,
   Aspect_Default_Iterator = Always_Delay,
+  Aspect_Default_Storage_Pool = Always_Delay,
   Aspect_Default_Value= Always_Delay,
   Aspect_Default_Component_Value  = Always_Delay,
   Aspect_Discard_Names= Always_Delay,
Index: sem_ch13.adb
===
--- sem_ch13.adb(revision 216925)
+++ sem_ch13.adb(working copy)
@@ -2236,6 +2236,20 @@
   Insert_Pragma (Aitem);
   goto Continue;
 
+   --  Default_Storage_Pool
+
+   when Aspect_Default_Storage_Pool =
+  Make_Aitem_Pragma
+(Pragma_Argument_Associations = New_List (
+   Make_Pragma_Argument_Association (Loc,
+ Expression = Relocate_Node (Expr))),
+ Pragma_Name  =
+   Name_Default_Storage_Pool);
+
+  Decorate (Aspect, Aitem);
+  Insert_Pragma (Aitem);
+  goto Continue;
+
--  Depends
 
--  Aspect Depends is never delayed because it is equivalent to
@@ -8693,6 +8707,9 @@
  when Aspect_Default_Component_Value =
 T := Component_Type (Entity (ASN));
 
+ when Aspect_Default_Storage_Pool =
+T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
+
  --  Default_Value is resolved with the type entity in question
 
  when Aspect_Default_Value =


[Ada] Inlining of calls to subprogram renamings

2014-10-31 Thread Arnaud Charlet
The compiler does not inline calls to entities which are subprogram
renamings. This is visible by means of the following small reproducer;
compiling the main unit without this patch the compiler reported a
the warning indicating inlining failed in call to R.Value

After this patch these sources are compiled silently.

generic
package G is
  function Value return Integer;
  pragma Inline (Value);
end G;

package body G is
   function Value2 return Integer is begin return 0; end;
   function Value return Integer renames Value2;
end G;

with G;
package R is new G;

with R;
package Q is
  generic
  procedure Proc_G;
end Q;

package body Q is
  procedure Proc_G is
C : constant Integer := R.Value;
  begin
null;
  end;
end Q;

with Q;
procedure P is
  procedure Proc is new Q.Proc_G;
begin
  Proc;
end;

Command: gcc -c p.adb -O -gnatn2 -Winline

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Javier Miranda  mira...@adacore.com

* inline.adb (Expand_Inlined_Call): Do not skip
inlining of calls to subprogram renamings.

Index: inline.adb
===
--- inline.adb  (revision 216959)
+++ inline.adb  (working copy)
@@ -2659,7 +2659,9 @@
   --  Body_To_Inline is also set for renamings (see sinfo.ads)
 
   elsif Nkind (Orig_Bod) in N_Entity then
- return;
+ if not Has_Pragma_Inline (Subp) then
+return;
+ end if;
 
   --  Skip inlining if the function returns an unconstrained type using
   --  an extended return statement since this part of the new inlining


Re: [PATCH v2] avoid alignment of static variables affecting stack's

2014-10-31 Thread Richard Biener
On Fri, Oct 24, 2014 at 4:57 PM, Jan Beulich jbeul...@suse.com wrote:
 Function (or more narrow) scope static variables (as well as others not
 placed on the stack) should also not have any effect on the stack
 alignment. I noticed the issue first with Linux'es dynamic_pr_debug()
 construct using an 8-byte aligned sub-file-scope local variable.

 According to my checking bad behavior started with 4.6.x (4.5.3 was
 still okay), but generated code got quite a bit worse as of 4.9.0.

 [v2: Drop inclusion of hard register variables, as requested by
  Jakub and Richard.]

I wonder if the spilling argument also holds true for those though,
as probably nothing guarantees that we don't re-load from the global
(the global may be more expensive to access than the stack).

Otherwise this looks ok, but maybe Vlad can chime in here.

Thanks,
Richard.

 gcc/
 2014-10-24  Jan Beulich  jbeul...@suse.com

 * cfgexpand.c (expand_one_var): Exclude static and external
 variables when adjusting stack alignment related state.

 gcc/testsuite/
 2014-10-24  Jan Beulich  jbeul...@suse.com

 * gcc.c-torture/execute/stkalign.c: New.

 --- a/gcc/cfgexpand.c
 +++ b/gcc/cfgexpand.c
 @@ -1233,12 +1233,15 @@ static HOST_WIDE_INT
  expand_one_var (tree var, bool toplevel, bool really_expand)
  {
unsigned int align = BITS_PER_UNIT;
 +  bool stack = true;
tree origvar = var;

var = SSAVAR (var);

if (TREE_TYPE (var) != error_mark_node  TREE_CODE (var) == VAR_DECL)
  {
 +  stack = !TREE_STATIC (var)  !DECL_EXTERNAL (var);
 +
/* Because we don't know if VAR will be in register or on stack,
  we conservatively assume it will be on stack even if VAR is
  eventually put into register after RA pass.  For non-automatic
 @@ -1267,22 +1270,25 @@ expand_one_var (tree var, bool toplevel,
 align = POINTER_SIZE;
  }

 -  if (SUPPORTS_STACK_ALIGNMENT
 -   crtl-stack_alignment_estimated  align)
 +  if (stack)
  {
 -  /* stack_alignment_estimated shouldn't change after stack
 - realign decision made */
 -  gcc_assert (!crtl-stack_realign_processed);
 -  crtl-stack_alignment_estimated = align;
 +  if (SUPPORTS_STACK_ALIGNMENT
 +  crtl-stack_alignment_estimated  align)
 +   {
 + /* stack_alignment_estimated shouldn't change after stack
 +realign decision made */
 + gcc_assert (!crtl-stack_realign_processed);
 + crtl-stack_alignment_estimated = align;
 +   }
 +
 +  /* stack_alignment_needed  PREFERRED_STACK_BOUNDARY is permitted.
 +So here we only make sure stack_alignment_needed = align.  */
 +  if (crtl-stack_alignment_needed  align)
 +   crtl-stack_alignment_needed = align;
 +  if (crtl-max_used_stack_slot_alignment  align)
 +   crtl-max_used_stack_slot_alignment = align;
  }

 -  /* stack_alignment_needed  PREFERRED_STACK_BOUNDARY is permitted.
 - So here we only make sure stack_alignment_needed = align.  */
 -  if (crtl-stack_alignment_needed  align)
 -crtl-stack_alignment_needed = align;
 -  if (crtl-max_used_stack_slot_alignment  align)
 -crtl-max_used_stack_slot_alignment = align;
 -
if (TREE_CODE (origvar) == SSA_NAME)
  {
gcc_assert (TREE_CODE (var) != VAR_DECL
 --- a/gcc/testsuite/gcc.c-torture/execute/stkalign.c
 +++ b/gcc/testsuite/gcc.c-torture/execute/stkalign.c
 @@ -0,0 +1,26 @@
 +/* { dg-options -fno-inline } */
 +
 +#include assert.h
 +
 +#define ALIGNMENT 64
 +
 +unsigned test(unsigned n, unsigned p)
 +{
 +  static struct { char __attribute__((__aligned__(ALIGNMENT))) c; } s;
 +  unsigned x;
 +
 +  assert(__alignof__(s) == ALIGNMENT);
 +  asm ( : =g (x), +m (s) : 0 (x));
 +
 +  return n ? test(n - 1, x) : (x ^ p);
 +}
 +
 +int main (int argc, char *argv[] __attribute__((unused)))
 +{
 +  unsigned int x = test(argc, 0);
 +
 +  x |= test(argc + 1, 0);
 +  x |= test(argc + 2, 0);
 +
 +  return !(x  (ALIGNMENT - 1));
 +}





Re: [PATCH] Fix VRP of UBSAN_SUB_CHECK (PR sanitizer/63697)

2014-10-31 Thread Richard Biener
On Fri, Oct 31, 2014 at 11:58 AM, Jakub Jelinek ja...@redhat.com wrote:
 Hi!

 This patch fixes a thinko in VRP of UBSAN_SUB_CHECK -
 if we have two VR_RANGEs for subtraction, to detect whether
 the subtraction might overflow we need to check if
 op0's minimum - op1's maximum overflow or if
 op0's maximum - op1's minimum overflow, while the code
 has been checking both maximums and minimums together instead
 (like is needed for UBSAN_ADD_CHECK; for UBSAN_MUL_CHECK
 we were testing all 4 combinations, so it should be fine).

 The attached testcase shows that this bug caused us to miss
 reporting one of the overflows.

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

Ok.

Thanks,
Richard.

 2014-10-31  Jakub Jelinek  ja...@redhat.com

 PR sanitizer/63697
 * tree-vrp.c (simplify_internal_call_using_ranges): For subcode ==
 MINUS_EXPR, check overflow on vr0.min - vr1.max and vr0.max - vr1.min
 instead of vr0.min - vr1.min and vr0.max - vr1.max.

 * c-c++-common/ubsan/overflow-sub-3.c: New test.

 --- gcc/tree-vrp.c.jj   2014-10-30 14:42:19.0 +0100
 +++ gcc/tree-vrp.c  2014-10-31 09:49:52.323772046 +0100
 @@ -9538,8 +9538,10 @@ simplify_internal_call_using_ranges (gim
  }
else
  {
 -  tree r1 = int_const_binop (subcode, vr0.min, vr1.min);
 -  tree r2 = int_const_binop (subcode, vr0.max, vr1.max);
 +  tree r1 = int_const_binop (subcode, vr0.min,
 +subcode == MINUS_EXPR ? vr1.max : vr1.min);
 +  tree r2 = int_const_binop (subcode, vr0.max,
 +subcode == MINUS_EXPR ? vr1.min : vr1.max);
if (r1 == NULL_TREE || TREE_OVERFLOW (r1)
   || r2 == NULL_TREE || TREE_OVERFLOW (r2))
 return false;
 --- gcc/testsuite/c-c++-common/ubsan/overflow-sub-3.c.jj2014-10-31 
 09:54:17.279910346 +0100
 +++ gcc/testsuite/c-c++-common/ubsan/overflow-sub-3.c   2014-10-31 
 09:54:13.194083245 +0100
 @@ -0,0 +1,34 @@
 +/* { dg-do run } */
 +/* { dg-options -fsanitize=signed-integer-overflow } */
 +
 +__attribute__((noinline, noclone)) int
 +foo1 (int x, int y)
 +{
 +  return x - y;
 +}
 +
 +__attribute__((noinline, noclone)) int
 +foo2 (int x, int y)
 +{
 +  unsigned int xa = (unsigned int) x - (__INT_MAX__ - 3);
 +  xa = 3;
 +  x = __INT_MAX__ - 3 + xa;
 +  unsigned int ya = y + 1U;
 +  ya = 1;
 +  y = ya - 1;
 +  return x - y;
 +}
 +
 +int
 +main ()
 +{
 +  int xm1, y;
 +  for (xm1 = __INT_MAX__ - 4; xm1  __INT_MAX__; xm1++)
 +for (y = -1; y = 0; y++)
 +  if (foo1 (xm1 + 1, y) != (int) (xm1 + 1U - y)
 + || foo2 (xm1 + 1, y) != (int) (xm1 + 1U - y))
 +   __builtin_abort ();
 +  return 0;
 +}
 +/* { dg-output :7:\[0-9]\[^\n\r]*signed integer overflow: 2147483647 - -1 
 cannot be represented in type 'int'\[^\n\r]*(\n|\r\n|\r) } */
 +/* { dg-output \[^\n\r]*:19:\[0-9]\[^\n\r]*signed integer overflow: 
 2147483647 - -1 cannot be represented in type 'int' } */

 Jakub


Re: [PATCH] Don't bootstrap libcc1

2014-10-31 Thread Richard Biener
On Fri, Oct 31, 2014 at 12:01 PM, Jakub Jelinek ja...@redhat.com wrote:
 On Thu, Oct 30, 2014 at 09:39:06AM +0100, Paolo Bonzini wrote:
  --- configure.ac   2014-10-28 14:39:53.018852391 +0100
  +++ configure.ac   2014-10-29 11:43:19.873216226 +0100
  @@ -2677,6 +2677,7 @@ for module in ${configdirs} ; do
 fi
 case ${module},${bootstrap_fixincludes} in
   fixincludes,no) host_bootstrap_suffix=no-bootstrap ;;
  +libcc1,*) host_bootstrap_suffix=no-bootstrap ;;
   *) host_bootstrap_suffix=$bootstrap_suffix ;;
 esac
 extrasub_host=$extrasub_host
 
  Makefile.def has:
  host_modules= { module= libcc1; bootstrap=true;
  extra_configure_flags=--enable-shared; };
  wonder if that bootstrap=true; is desirable there.

 No, it shouldn't be there

 Seems removing that makes the configure.ac change unneeded.
 Bootstrapped/regtested on x86_64-linux and i686-linux (libcc1
 is built after compare, by stage3 compiler), and built
 with --disable-bootstrap on i686-linux (libcc1 is built by
 the system compiler in that case).  Ok for trunk?

Ok.

Thanks,
Richard.

 2014-10-31  Jakub Jelinek  ja...@redhat.com

 * Makefile.def (libcc1): Remove bootstrap=true;.
 * Makefile.in: Regenerated.

 --- Makefile.def.jj 2014-10-28 14:40:30.0 +0100
 +++ Makefile.def2014-10-31 10:10:22.723173845 +0100
 @@ -123,8 +123,7 @@ host_modules= { module= gnattools; };
  host_modules= { module= lto-plugin; bootstrap=true;
 extra_configure_flags='--enable-shared 
 @extra_linker_plugin_flags@ @extra_linker_plugin_configure_flags@';
 extra_make_flags='@extra_linker_plugin_flags@'; };
 -host_modules= { module= libcc1; bootstrap=true;
 -   extra_configure_flags=--enable-shared; };
 +host_modules= { module= libcc1; extra_configure_flags=--enable-shared; };

  target_modules = { module= libstdc++-v3;
bootstrap=true;
 --- Makefile.in.jj  2014-10-28 14:39:52.0 +0100
 +++ Makefile.in 2014-10-31 10:10:51.0 +0100
 @@ -1085,9 +1085,7 @@ all-host: maybe-all-gnattools
  @if lto-plugin-no-bootstrap
  all-host: maybe-all-lto-plugin
  @endif lto-plugin-no-bootstrap
 -@if libcc1-no-bootstrap
  all-host: maybe-all-libcc1
 -@endif libcc1-no-bootstrap

  .PHONY: all-target

 @@ -32264,6 +32262,7 @@ configure-libcc1: stage_current
  @if libcc1
  maybe-configure-libcc1: configure-libcc1
  configure-libcc1:
 +   @: $(MAKE); $(unstage)
 @r=`${PWD_COMMAND}`; export r; \
 s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 test ! -f $(HOST_SUBDIR)/libcc1/Makefile || exit 0; \
 @@ -32287,211 +32286,6 @@ configure-libcc1:



 -.PHONY: configure-stage1-libcc1 maybe-configure-stage1-libcc1
 -maybe-configure-stage1-libcc1:
 -@if libcc1-bootstrap
 -maybe-configure-stage1-libcc1: configure-stage1-libcc1
 -configure-stage1-libcc1:
 -   @[ $(current_stage) = stage1 ] || $(MAKE) stage1-start
 -   @$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/libcc1
 -   @r=`${PWD_COMMAND}`; export r; \
 -   s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 -   TFLAGS=$(STAGE1_TFLAGS); \
 -   test ! -f $(HOST_SUBDIR)/libcc1/Makefile || exit 0; \
 -   $(HOST_EXPORTS) \
 -   CFLAGS=$(STAGE1_CFLAGS); export CFLAGS; \
 -   CXXFLAGS=$(STAGE1_CXXFLAGS); export CXXFLAGS; \
 -   LIBCFLAGS=$(LIBCFLAGS); export LIBCFLAGS;  \
 -   echo Configuring stage 1 in $(HOST_SUBDIR)/libcc1 ; \
 -   $(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/libcc1 ; \
 -   cd $(HOST_SUBDIR)/libcc1 || exit 1; \
 -   case $(srcdir) in \
 - /* | [A-Za-z]:[\\/]*) topdir=$(srcdir) ;; \
 - *) topdir=`echo $(HOST_SUBDIR)/libcc1/ | \
 -   sed -e 's,\./,,g' -e 's,[^/]*/,../,g' `$(srcdir) ;; \
 -   esac; \
 -   module_srcdir=libcc1; \
 -   $(SHELL) $$s/$$module_srcdir/configure \
 - --srcdir=$${topdir}/$$module_srcdir \
 - $(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
 - --target=${target_alias} \
 -  \
 - $(STAGE1_CONFIGURE_FLAGS) \
 - --enable-shared
 -@endif libcc1-bootstrap
 -
 -.PHONY: configure-stage2-libcc1 maybe-configure-stage2-libcc1
 -maybe-configure-stage2-libcc1:
 -@if libcc1-bootstrap
 -maybe-configure-stage2-libcc1: configure-stage2-libcc1
 -configure-stage2-libcc1:
 -   @[ $(current_stage) = stage2 ] || $(MAKE) stage2-start
 -   @$(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/libcc1
 -   @r=`${PWD_COMMAND}`; export r; \
 -   s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
 -   TFLAGS=$(STAGE2_TFLAGS); \
 -   test ! -f $(HOST_SUBDIR)/libcc1/Makefile || exit 0; \
 -   $(HOST_EXPORTS) \
 -   $(POSTSTAGE1_HOST_EXPORTS) \
 -   CFLAGS=$(STAGE2_CFLAGS); export CFLAGS; \
 -   CXXFLAGS=$(STAGE2_CXXFLAGS); export CXXFLAGS; \
 -   LIBCFLAGS=$(STAGE2_CFLAGS); export LIBCFLAGS;  \
 -   echo Configuring stage 2 in $(HOST_SUBDIR)/libcc1 ; \
 -   

[Ada] Remove unreachable inlining code

2014-10-31 Thread Arnaud Charlet
This removes unreachable code for back-end inlining in Expand_Call.

No functional changes.

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Eric Botcazou  ebotca...@adacore.com

* exp_ch6.adb (Do_Inline): Remove unreachable code.
(Do_Inline_Always): Likewise.

Index: exp_ch6.adb
===
--- exp_ch6.adb (revision 216925)
+++ exp_ch6.adb (working copy)
@@ -1998,19 +1998,6 @@
   --  expression for the value of the actual, EF is the entity for the
   --  extra formal.
 
-  procedure Do_Inline (Subp : Entity_Id; Orig_Subp : Entity_Id);
-  --  Check and inline the body of Subp. Invoked when compiling with
-  --  optimizations enabled and Subp has pragma inline or inline always.
-  --  If the subprogram is a renaming, or if it is inherited, then Subp
-  --  references the renamed entity and Orig_Subp is the entity of the
-  --  call node N.
-
-  procedure Do_Inline_Always (Subp : Entity_Id; Orig_Subp : Entity_Id);
-  --  Check and inline the body of Subp. Invoked when compiling without
-  --  optimizations and Subp has pragma inline always. If the subprogram is
-  --  a renaming, or if it is inherited, then Subp references the renamed
-  --  entity and Orig_Subp is the entity of the call node N.
-
   function Inherited_From_Formal (S : Entity_Id) return Entity_Id;
   --  Within an instance, a type derived from an untagged formal derived
   --  type inherits from the original parent, not from the actual. The
@@ -2097,211 +2084,6 @@
  end if;
   end Add_Extra_Actual;
 
-  
-  --  Do_Inline --
-  
-
-  procedure Do_Inline (Subp : Entity_Id; Orig_Subp : Entity_Id) is
- Spec : constant Node_Id := Unit_Declaration_Node (Subp);
-
- procedure Do_Backend_Inline;
- --  Check that the call can be safely passed to the backend. If true
- --  then register the enclosing unit of Subp to Inlined_Bodies so that
- --  the body of Subp can be retrieved and analyzed by the backend.
-
- ---
- -- Do_Backend_Inline --
- ---
-
- procedure Do_Backend_Inline is
- begin
---  No extra test needed for init subprograms since we know they
---  are available to the backend.
-
-if Is_Init_Proc (Subp) then
-   Add_Inlined_Body (Subp);
-   Register_Backend_Call (Call_Node);
-
---  Verify that if the body to inline is located in the current
---  unit the inlining does not occur earlier. This avoids
---  order-of-elaboration problems in the back end.
-
-elsif In_Same_Extended_Unit (Call_Node, Subp)
-  and then Nkind (Spec) = N_Subprogram_Declaration
-  and then Earlier_In_Extended_Unit
- (Loc, Sloc (Body_To_Inline (Spec)))
-then
-   Error_Msg_NE
- (cannot inline (body not seen yet)??, Call_Node, Subp);
-
-else
-   declare
-  Backend_Inline : Boolean := True;
-
-   begin
-  --  If we are compiling a package body that is not the
-  --  main unit, it must be for inlining/instantiation
-  --  purposes, in which case we inline the call to insure
-  --  that the same temporaries are generated when compiling
-  --  the body by itself. Otherwise link errors can occur.
-
-  --  If the function being called is itself in the main
-  --  unit, we cannot inline, because there is a risk of
-  --  double elaboration and/or circularity: the inlining
-  --  can make visible a private entity in the body of the
-  --  main unit, that gigi will see before its sees its
-  --  proper definition.
-
-  if not (In_Extended_Main_Code_Unit (Call_Node))
-and then In_Package_Body
-  then
- Backend_Inline :=
-   not In_Extended_Main_Source_Unit (Subp);
-  end if;
-
-  if Backend_Inline then
- Add_Inlined_Body (Subp);
- Register_Backend_Call (Call_Node);
-  end if;
-   end;
-end if;
- end Do_Backend_Inline;
-
-  --  Start of processing for Do_Inline
-
-  begin
- --  Verify that the body to inline has already been seen
-
- if No (Spec)
-   or else Nkind (Spec) /= N_Subprogram_Declaration
-   or else No (Body_To_Inline (Spec))
- then
-if Comes_From_Source (Subp)
-  and then Must_Inline (Subp)
-then
-   Cannot_Inline
- 

[Ada] Changes related to back-end inlining

2014-10-31 Thread Arnaud Charlet
This change affects only back-end inlining and is two-fold:

1. It lifts in a 3rd place the limitation associated with
nested subprograms as well as with a couple of other constructs.
After it is applied, the only significant limitation left are
the nested packages.

2. It makes sure the errors associated with pragma Inline_Always
are issued whatever the optimization level, which is in keeping
with its semantics.

It makes it possible to inline/reject consistently at all
optimization levels subprograms marked with pragma Inline_Always,
for example:

package Q is
   procedure Test (I : Integer);
   pragma Inline_Always (Test);
end Q;
package body Q is
   procedure Test (I : Integer) is
  -- Uncomment to make it compile
  -- function F (J : Integer) return Integer;
  -- pragma Inline_Always (F);

  function F (J : Integer) return Integer is
  begin
 return I - J;
  end;

   begin
  if I /= F (I) then raise Program_Error; end if;
   end;
end Q;

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Eric Botcazou  ebotca...@adacore.com

* inline.adb (Has_Excluded_Declaration): With back-end inlining,
only return true for nested packages.
(Cannot_Inline): Issue errors/warnings whatever the optimization level
for back-end inlining and remove assertion.

Index: inline.adb
===
--- inline.adb  (revision 216960)
+++ inline.adb  (working copy)
@@ -1225,10 +1225,8 @@
 Error_Msg_NE (Msg  p?, N, Subp);
  end if;
 
- return;
+  --  New semantics relying on back end inlining
 
-  --  New semantics
-
   elsif Is_Serious then
 
  --  Remove last character (question mark) to make this into an error.
@@ -1242,10 +1240,8 @@
  Set_Is_Inlined_Always (Subp, False);
  Error_Msg_NE (Msg  p?, N, Subp);
 
-  --  Do not issue errors/warnings when compiling with optimizations
+  else
 
-  elsif Optimization_Level = 0 then
-
  --  Do not emit warning if this is a predefined unit which is not
  --  the main unit. This behavior is currently provided for backward
  --  compatibility but it will be removed when we enforce the
@@ -1281,24 +1277,13 @@
 
 Error_Msg_NE (Msg (Msg'First .. Msg'Last - 1), N, Subp);
 
- else pragma Assert (Front_End_Inlining);
+ else
 Set_Is_Inlined (Subp, False);
 
---  When inlining cannot take place we must issue an error.
---  For backward compatibility we still report a warning.
-
 if Ineffective_Inline_Warnings then
Error_Msg_NE (Msg  p?, N, Subp);
 end if;
  end if;
-
-  --  Compiling with optimizations enabled it is too early to report
-  --  problems since the backend may still perform inlining. In order
-  --  to report unhandled inlinings the program must be compiled with
-  --  -Winline and the error is reported by the backend.
-
-  else
- null;
   end if;
end Cannot_Inline;
 
@@ -3327,12 +3312,26 @@
 
   D := First (Decls);
   while Present (D) loop
- if Nkind (D) = N_Subprogram_Body then
+ --  First declarations universally excluded
+
+ if Nkind (D) = N_Package_Declaration then
 Cannot_Inline
-  (cannot inline  (nested subprogram)?,
+  (cannot inline  (nested package declaration)?,
D, Subp);
 return True;
 
+ elsif Nkind (D) = N_Package_Instantiation then
+Cannot_Inline
+  (cannot inline  (nested package instantiation)?,
+   D, Subp);
+return True;
+ end if;
+
+ --  Then declarations excluded only for front end inlining
+
+ if Back_End_Inlining then
+null;
+
  elsif Nkind (D) = N_Task_Type_Declaration
or else Nkind (D) = N_Single_Task_Declaration
  then
@@ -3349,9 +3348,9 @@
D, Subp);
 return True;
 
- elsif Nkind (D) = N_Package_Declaration then
+ elsif Nkind (D) = N_Subprogram_Body then
 Cannot_Inline
-  (cannot inline  (nested package declaration)?,
+  (cannot inline  (nested subprogram)?,
D, Subp);
 return True;
 
@@ -3368,12 +3367,6 @@
   (cannot inline  (nested procedure instantiation)?,
D, Subp);
 return True;
-
- elsif Nkind (D) = N_Package_Instantiation then
-Cannot_Inline
-  (cannot inline  (nested package instantiation)?,
-   D, Subp);
-return True;
  end if;
 
  Next (D);


[Ada] Implementation of Default_Pool pragma

2014-10-31 Thread Arnaud Charlet
This patch adds missing semantic checks to the implementation of the Ada2012
aspect Default_Storage_Pool.

Compiling bdb3dbm0.adb must yield:

   bdb3dbm0.adb:17:45: default storage pool must be a variable
   bdb3dbm0.adb:19:33:
expected type System.Storage_Pools.Root_Storage_Pool'CLASS
   bdb3dbm0.adb:19:33: found type Non_Pool_Type defined at line 11
   bdb3dbm0.adb:23:36: default storage pool must be a variable

---
with FDB0A00;
with System.Storage_Elements;

procedure BDB3DBM0 is
   Pool : aliased FDB0A00.Stack_Heap (Water_Line = 24);

   type Frozen_Pool_Type is access constant FDB0A00.Stack_Heap;

   Frozen_Pool : Frozen_Pool_Type := Pool'Access;

   type Non_Pool_Type is tagged null record;

   Non_Pool : Non_Pool_Type;

   pragma Default_Storage_Pool (Pool);-- OK.

   pragma Default_Storage_Pool (Frozen_Pool.all); -- ERROR:

   pragma Default_Storage_Pool (Non_Pool_Type);  -- ERROR:

   procedure Constant_Pool (Local_Pool : in FDB0A00.Stack_Heap)
   is
  pragma Default_Storage_Pool (Local_Pool);   -- ERROR:

  type String_Access is access String;
  S : String_Access;
   begin
  S := new String'(Hello);
   end Constant_Pool;

begin

   Constant_Pool (Pool);

end BDB3DBM0;
---
with Report;
with System.Storage_Pools;
with System.Storage_Elements;
package FDB0A00 is

  type Stack_Heap( Water_Line: System.Storage_Elements.Storage_Count )
 is new System.Storage_Pools.Root_Storage_Pool with private;

  procedure Allocate(
Pool : in out Stack_Heap;
Storage_Address : out System.Address;
Size_In_Storage_Elements : in System.Storage_Elements.Storage_Count;
Alignment : in System.Storage_Elements.Storage_Count);

  procedure Deallocate(
Pool : in out Stack_Heap;
Storage_Address : in System.Address;
Size_In_Storage_Elements : in System.Storage_Elements.Storage_Count;
Alignment : in System.Storage_Elements.Storage_Count);

  function Storage_Size( Pool: in Stack_Heap )
   return System.Storage_Elements.Storage_Count;

  function TC_Largest_Request return System.Storage_Elements.Storage_Count;

  Pool_Overflow : exception;

private

  type Data_Array is array(System.Storage_Elements.Storage_Count range )
 of System.Storage_Elements.Storage_Element;

  type Stack_Heap( Water_Line: System.Storage_Elements.Storage_Count )
 is new System.Storage_Pools.Root_Storage_Pool with record
   Data  : Data_Array(1..Water_Line);
   Avail : System.Storage_Elements.Storage_Count := 1;
  end record;

end FDB0A00;
--
pragma Elaboration_Checks (Dynamic);
PACKAGE REPORT IS
 pragma Elaborate_Body;
 SUBTYPE FILE_NUM IS INTEGER RANGE 1..3;
 PROCEDURE TEST (NAME : STRING; DESCR : STRING ); 
 PROCEDURE FAILED (DESCR : STRING ); 
 PROCEDURE NOT_APPLICABLE (DESCR : STRING ); 
 PROCEDURE SPECIAL_ACTION (DESCR : STRING );
 PROCEDURE COMMENT (DESCR : STRING );
 PROCEDURE RESULT;
 FUNCTION IDENT_INT (X : INTEGER ) RETURN INTEGER; 
 FUNCTION IDENT_CHAR (X : CHARACTER ) RETURN CHARACTER;
 FUNCTION IDENT_WIDE_CHAR (X : WIDE_CHARACTER) RETURN WIDE_CHARACTER;
 FUNCTION IDENT_BOOL (X : BOOLEAN ) RETURN BOOLEAN;
 FUNCTION IDENT_STR (X : STRING ) RETURN STRING;
 FUNCTION IDENT_WIDE_STR (X : WIDE_STRING ) RETURN WIDE_STRING;
 FUNCTION EQUAL (X, Y : INTEGER ) RETURN BOOLEAN;   
 FUNCTION LEGAL_FILE_NAME (X : FILE_NUM := 1;
  NAM : STRING := )
  RETURN STRING;
END REPORT;

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Ed Schonberg  schonb...@adacore.com

* freeze.adb (Freeze_Entity): A default_pool does not apply to
internal access types generated for 'access references.
* sem_prag (Analyze_Pragma, case Default_Pool): If the name is
not null it must designate a variable.

Index: sem_prag.adb
===
--- sem_prag.adb(revision 216925)
+++ sem_prag.adb(working copy)
@@ -12945,11 +12945,16 @@
end if;
 
--  The expected type for a non-null argument is
-   --  Root_Storage_Pool'Class.
+   --  Root_Storage_Pool'Class, and the pool must be a variable.
 
Analyze_And_Resolve
  (Get_Pragma_Arg (Arg1),
   Typ = Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
+
+   if not Is_Variable (Expression (Arg1)) then
+  Error_Pragma_Arg
+(default storage pool must be a variable, Arg1);
+   end if;
 end if;
 
 --  Finally, record the pool name (or null). Freeze.Freeze_Entity
Index: freeze.adb
===
--- freeze.adb  (revision 216956)
+++ freeze.adb  (working copy)
@@ -5383,8 +5383,13 @@
Check_Suspicious_Modulus (E);
 end if;
 
+  

[Ada] Derived type whose parent has a full view with access discriminants

2014-10-31 Thread Arnaud Charlet
An access discriminant has an anonymous access type whose scope is the
enclosing package. If a derived type inherits access discriminants, their
itypes needs to be referenced in the current scope before the bodies of
primitive operations for the derived type are elaborated, to ensure that the
first reference to those itypes appears in the proper scope.

The package b,adb must compile quietly.

---
package A is
   type T1 () is tagged limited private; 
   function T1_Ctor return T1; 
private 
   type T1 (I_Ptr : access Integer) is tagged limited null record; 
end A;
---
package body A is 
   function T1_Ctor return T1 is 
   begin 
  return (I_Ptr = null); 
   end T1_Ctor; 
end A;
---
with A; 
package B is 
   type T2 () is new A.T1 with private; 
   function T2_Ctor return T2; 
private 
  type T2 is new A.T1 with null record; 
end B;
---
package body B is 
   function T2_Ctor return T2 is 
   begin 
  return T2'(A.T1_Ctor with null record); 
   end T2_Ctor; 
end B;

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Ed Schonberg  schonb...@adacore.com

* sem_ch3.adb (Build_Derived_Private_Type): If the derived
type has access discriminants, create itype references for their
anonymous types, so that they are elaborated before the generated
bodies for the primitive operations of the type.

Index: sem_ch3.adb
===
--- sem_ch3.adb (revision 216925)
+++ sem_ch3.adb (working copy)
@@ -6943,6 +6943,28 @@
 
Set_Is_Frozen (Full_Der);
 
+   --  If the derived type has access discriminants, create
+   --  references to their anonymous types now, to prevent
+   --  back-end problems when their first use is in generated
+   --  bodies of primitives.
+
+   declare
+  E : Entity_Id;
+
+   begin
+  E := First_Entity (Full_Der);
+
+  while Present (E) loop
+ if Ekind (E) = E_Discriminant
+   and then Ekind (Etype (E)) = E_Anonymous_Access_Type
+ then
+Build_Itype_Reference (Etype (E), Decl);
+ end if;
+
+ Next_Entity (E);
+  end loop;
+   end;
+
--  Set up links between real entity and underlying record view
 
Set_Underlying_Record_View (Derived_Type, Base_Type (Full_Der));


[PATCH] Use NOP_EXPRs from genmatch

2014-10-31 Thread Richard Biener
This makes genmatch emit NOP_EXPRs instead of CONVERT_EXPRs.
This avoids various corner cases in passes, fold and FE-ish code.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2014-10-31  Richard Biener  rguent...@suse.de

* genmatch.c (expr::gen_transform): Use NOP_EXPRs instead of
CONVERT_EXPRs in generated code.
(dt_simplify::gen): Likewise.


p2
Description: Binary data


[PATCH][AArch64] Properly guard CUMULATIVE_ARGS definition and remove 'enum' from machine_mode in aarch64.h

2014-10-31 Thread Kyrill Tkachov

Hi all,

Following up from 
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg03153.html this fixes up 
the aarch64 port
accordingly to guard CUMULATIVE_ARGS properly so that we can remove the 
enum keyword from machine_mode.


Building aarch64-none-elf succeeds (after reverting my previous patch).

Ok for trunk?

Thanks,
Kyrill

2014-10-31  Kyrylo Tkachov  kyrylo.tkac...@arm.com

* config/aarch64/aarch64.h (MACHMODE): Remove 'enum' keyword.
(CUMULATIVE_ARGS): Guard on !defined(USED_FOR_TARGET).diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 97b1848..c37d4b1 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -611,10 +611,10 @@ enum arm_pcs
 #define MACHMODE int
 #else
 #include insn-modes.h
-#define MACHMODE enum machine_mode
+#define MACHMODE machine_mode
 #endif
 
-
+#ifndef USED_FOR_TARGET
 /* AAPCS related state tracking.  */
 typedef struct
 {
@@ -635,6 +635,7 @@ typedef struct
   int aapcs_stack_size;		/* The total size (in words, per 8 byte) of the
    stack arg area so far.  */
 } CUMULATIVE_ARGS;
+#endif
 
 #define FUNCTION_ARG_PADDING(MODE, TYPE) \
   (aarch64_pad_arg_upward (MODE, TYPE) ? upward : downward)

[Ada] Missing check on interface primitives

2014-10-31 Thread Arnaud Charlet
The compiler does not not verify always that all the primitives of an
interface type are abstract or null procedures. After this patch the
following test is compiled with errors:

package Pkg is
   --  Test 1
   type IA is tagged;
   function Get_myB (Self : IA) return natural;

   type IA is interface;

   --  Test 2
   type Iface is interface;
   function f1 (Obj : Iface) return Natural is (0);
end;

Command: gcc -c pkg.ads
Output:
pkg.ads:4:04: interface function Get_Myb must be abstract
pkg.ads:10:04: interface function F1 must be abstract

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Javier Miranda  mira...@adacore.com

* freeze.adb (Freeze_Record_Type): Add missing
check to verify that all the primitives of an interface type
are abstract or null procedures.

Index: freeze.adb
===
--- freeze.adb  (revision 216963)
+++ freeze.adb  (working copy)
@@ -4004,6 +4004,47 @@
 --  call to the Analyze_Freeze_Entity for the record type.
 
  end Check_Variant_Part;
+
+ --  Check that all the primitives of an interface type are abstract
+ --  or null procedures.
+
+ if Is_Interface (Rec)
+   and then not Error_Posted (Parent (Rec))
+ then
+declare
+   Elmt : Elmt_Id;
+   Subp : Entity_Id;
+
+begin
+   Elmt := First_Elmt (Primitive_Operations (Rec));
+   while Present (Elmt) loop
+  Subp := Node (Elmt);
+
+  if not Is_Abstract_Subprogram (Subp)
+
+ --  Avoid reporting the error on inherited primitives
+
+and then Comes_From_Source (Subp)
+  then
+ Error_Msg_Name_1 := Chars (Subp);
+
+ if Ekind (Subp) = E_Procedure then
+if not Null_Present (Parent (Subp)) then
+   Error_Msg_N
+ (interface procedure % must be abstract or null,
+  Parent (Subp));
+end if;
+ else
+Error_Msg_N
+  (interface function % must be abstract,
+   Parent (Subp));
+ end if;
+  end if;
+
+  Next_Elmt (Elmt);
+   end loop;
+end;
+ end if;
   end Freeze_Record_Type;
 
   ---


Re: [PATCH, committed] AIX libstdc++ configure.host LD_FLAGS

2014-10-31 Thread Michael Haubenwallner
On 10/30/2014 03:19 PM, David Edelsohn wrote:
 AIX has been unable to bootstrap since the match-and-simplify merge.
 Richard Biener and I tracked this back to a bad interaction between a
 GCC optimization and the AIX linker -G option to allow for SVR4-style
 runtime linking.

As the -G linker option is the equivalent of specifying the options
-berok -brtl -bnortllib -bnosymbolic -bnoautoexp -bM:SRE, did you
track down which one exactly interacts with that GCC optimization?

Background is that I do rely on the -brtl linker flag actually, to
allow Linux-like filename-based sharedlib versioning, using plain text
Import Files as member of the libstdc++.so archive. We talked about
that years ago, and I do plan to redo aix-soname for gcc-trunk.

 The following patch removes the linker option from the libstdc++
 build.  This will prevent runtime function interposition, e.g.
 overriding operator new, when using libstdc++, but that is rarely
 needed.

While I agree things like overriding operator new is rarely needed, I
doubt it is acceptable to prevent this deliberately on an otherwise
fully supportable platform. As far as I can see, even IBM is after
getting as many Linux-known features as possible into AIX...

Would it work to use sth. like -G -bsymbolic instead?

Thanks!
/haubi/

 
 This patch also uses the default atomic support
 
 Bootstrapped on powerpc-ibm-aix7.1.0.0
 
 2014-10-30  David Edelsohn  dje@gmail.com
 
 * configure.host (aix5+): New stanza.
 (aix4.3+): Do not use -G in link command.
 
 Index: configure.host
 ===
 --- configure.host  (revision 216851)
 +++ configure.host  (working copy)
 @@ -212,14 +212,20 @@
  # CPU-specifc, set those here too.
  # THIS TABLE IS SORTED.  KEEP IT THAT WAY.
  case ${host_os} in
 -  aix4.[3456789]* | aix[56789]*)
 +  aix[56789]*)
 +# Newer versions of AIX only support PowerPC architecture, so use
 +# atomic instructions directly.
 +os_include_dir=os/aix
 +atomicity_dir=cpu/generic
 +atomic_word_dir=os/aix
 +;;
 +  aix4.[3456789]*)
  # We set os_include_dir to os/aix only on AIX 4.3 and newer, but
  # os/aix/atomicity.h works on earlier versions of AIX 4.*, so we
  # explicitly duplicate the directory for 4.[3].
  os_include_dir=os/aix
  atomicity_dir=os/aix
  atomic_word_dir=os/aix
 -OPT_LDFLAGS=-Wl,-G
  ;;
aix4.*)
  os_include_dir=os/generic
 



[PATCH] Use CONVERT_EXPR_P and friends in the middle-end

2014-10-31 Thread Richard Biener
This fixes the few places where explicit checks for NOP_EXPR
or CONVERT_EXPRs crept in.

A noticable change may be the tree-eh.c one where we previously
considered FP NOP_EXPRs trapping if flag_trapping_math
(Any fp arithmetic may trap) but now like FP CONVERT_EXPRs
only when honor_nans (but for some reason the honor_nans
cases don't check flag_trapping_math).  I'm not 100% sure which
variant is more correct (this is FP - FP conversions thus
widenings, truncations, converts from/to DFP).

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2014-10-31  Richard Biener  rguent...@suse.de

* builtins.c (fold_builtin_atomic_always_lock_free): Use
CONVERT_EXPR_P, CONVERT_EXPR_CODE_P and CASE_CONVERT where
approprate.
(fold_builtin_expect): Likewise.
(integer_valued_real_p): Likewise.
* cfgexpand.c (expand_debug_expr): Likewise.
* ipa-inline-analysis.c (eliminated_by_inlining_prob): Likewise.
(find_foldable_builtin_expect): Likewise.
* trans-mem.c (thread_private_new_memory): Likewise.
* tree-affine.c (aff_combination_expand): Likewise.
* tree-data-ref.c (initialize_matrix_A): Likewise.
* tree-eh.c (operation_could_trap_helper_p): Likewise.
* tree-inline.c (copy_bb): Likewise.
* tree-pretty-print.c (dump_function_name): Likewise.
(print_call_name): Likewise.
* tree-ssa-forwprop.c (constant_pointer_difference): Likewise.
* tree-ssa-math-opts.c (find_bswap_or_nop_1): Likewise.
* tree-vect-generic.c (expand_vector_operations_1): Likewise.
* tree-vect-patterns.c (vect_handle_widen_op_by_const): Likewise.
(vect_recog_widen_mult_pattern): Likewise.
(vect_operation_fits_smaller_type): Likewise.
* tree-vrp.c (find_assert_locations_1): Likewise.
* tree-ssa-dom.c (initialize_hash_element): Canonicalize
converts to NOP_EXPR.


p3
Description: Binary data


[Ada] New and updated library units for efficient and formal vectors

2014-10-31 Thread Arnaud Charlet
A new unit Ada.Containers.Formal_Indefinite_Vectors is introduced, which
defines vectors possibly holding indefinite elements, such as classwide
objects. The API of this new unit is based on the existing unit
Ada.Containers.Formal_Vectors which has been simplified in favor of
efficiency and provability. Both units can be used from client code in
SPARK and the simplification of the API is conducing to better automatic
proof of client code with GNATprove. Both units define a vector type that
can now be defined as bounded (with a maximal size fixed at declaration)
or not (in which case dynamic allocation is used to grow the vector when
the maximum size has been reached).

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Yannick Moy  m...@adacore.com

* Makefile.rtl, gnat_rm.texi, impunit.adb: Add mention of new library
files.
* a-cfinve.adb, a-cfinve.ads: New unit for formal indefinite
vectors, suitable for use in client SPARK code, also more
efficient than the standard vectors.
* a-coboho.adb, a-coboho.ads New unit for bounded holders, that
are used to define formal indefinite vectors in terms of formal
definite ones.
* a-cofove.adb, a-cofove.ads: Simplification of the API of formal
definite vectors, similar to the API of the new indefinite ones. A
new formal parameter of the generic unit called Bounded allows
to define growable vectors that use dynamic allocation.

Index: gnat_rm.texi
===
--- gnat_rm.texi(revision 216956)
+++ gnat_rm.texi(working copy)
@@ -542,6 +542,8 @@
 * Ada.Containers.Formal_Ordered_Maps (a-cforma.ads)::
 * Ada.Containers.Formal_Ordered_Sets (a-cforse.ads)::
 * Ada.Containers.Formal_Vectors (a-cofove.ads)::
+* Ada.Containers.Formal_Indefinite_Vectors (a-cfinve.ads)::
+* Ada.Containers.Bounded_Holders (a-coboho.ads)::
 * Ada.Command_Line.Environment (a-colien.ads)::
 * Ada.Command_Line.Remove (a-colire.ads)::
 * Ada.Command_Line.Response_File (a-clrefi.ads)::
@@ -5165,6 +5167,10 @@
 enumeration type not marked with pragma @code{Ordered} will be considered
 as unordered, and will generate warnings for inappropriate uses.
 
+Note that generic types are not considered ordered or unordered (since the
+template can be instantiated for both cases), so we never generate warnings
+for the case of generic enumerated types.
+
 For additional information please refer to the description of the
 @option{-gnatw.u} switch in the @value{EDITION} User's Guide.
 
@@ -19022,6 +19028,8 @@
 * Ada.Containers.Formal_Ordered_Maps (a-cforma.ads)::
 * Ada.Containers.Formal_Ordered_Sets (a-cforse.ads)::
 * Ada.Containers.Formal_Vectors (a-cofove.ads)::
+* Ada.Containers.Formal_Indefinite_Vectors (a-cfinve.ads)::
+* Ada.Containers.Bounded_Holders (a-coboho.ads)::
 * Ada.Command_Line.Environment (a-colien.ads)::
 * Ada.Command_Line.Remove (a-colire.ads)::
 * Ada.Command_Line.Response_File (a-clrefi.ads)::
@@ -19325,6 +19333,31 @@
 efficient version than the one defined in the standard. In particular it
 does not have the complex overhead required to detect cursor tampering.
 
+@node Ada.Containers.Formal_Indefinite_Vectors (a-cfinve.ads)
+@section @code{Ada.Containers.Formal_Indefinite_Vectors} (@file{a-cfinve.ads})
+@cindex @code{Ada.Containers.Formal_Indefinite_Vectors} (@file{a-cfinve.ads})
+@cindex Formal container for vectors
+
+@noindent
+This child of @code{Ada.Containers} defines a modified version of the
+Ada 2005 container for vectors of indefinite elements, meant to
+facilitate formal verification of code using such containers. The
+specification of this unit is compatible with SPARK 2014.
+
+Note that although this container was designed with formal verification
+in mind, it may well be generally useful in that it is a simplified more
+efficient version than the one defined in the standard. In particular it
+does not have the complex overhead required to detect cursor tampering.
+
+@node Ada.Containers.Bounded_Holders (a-coboho.ads)
+@section @code{Ada.Containers.Bounded_Holders} (@file{a-coboho.ads})
+@cindex @code{Ada.Containers.Bounded_Holders} (@file{a-coboho.ads})
+@cindex Formal container for vectors
+
+@noindent
+This child of @code{Ada.Containers} defines a modified version of
+Indefinite_Holders that avoids heap allocation.
+
 @node Ada.Command_Line.Environment (a-colien.ads)
 @section @code{Ada.Command_Line.Environment} (@file{a-colien.ads})
 @cindex @code{Ada.Command_Line.Environment} (@file{a-colien.ads})
Index: impunit.adb
===
--- impunit.adb (revision 216925)
+++ impunit.adb (working copy)
@@ -581,6 +581,8 @@
-- GNAT Defined Additions to Ada 2012 --

 
+(a-cfinve, F),  -- Ada.Containers.Formal_Indefinite_Vectors
+(a-coboho, F),  -- Ada.Containers.Bounded_Holders
 (a-cofove, F),  

[Ada] Handling of Default_Storage_Pool in generics and instantiations.

2014-10-31 Thread Arnaud Charlet
If there is a non-null default storage pool, a generic unit uses it for the
allocators it may contain.  At the point of instantiation, that default must
be installed so that it applies to the allocators in the instance. This is
achieved by adding an aspect specification Default_Storage_Pool to the generic,
and propagating it to each instance.

However, an instantiation may specify a different storage pool by means of the
same aspect, which then overrides the one inherited from the generic unit.
This patch implements both of these uses of default storage pools.

No simple test available. Full test is proposed ACATS test cdb3dbm0.

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Ed Schonberg  schonb...@adacore.com

* sem_ch12.adb (Analyze_Generic_Package_Declaration): If there
is a default storage pool, add a corresponding aspect to the
generic unit, to be used at the point of instantiation.
(Analyze_Package_Instantiation): If generic unit has aspect
specifications, propagate them to instance. If instance has a
Default_Storage_Pool aspect, make sure that it overrides the
one that may be inherited from the generic.

Index: sem_ch12.adb
===
--- sem_ch12.adb(revision 216963)
+++ sem_ch12.adb(working copy)
@@ -3437,6 +3437,27 @@
 Check_References (Id);
  end if;
   end if;
+
+  --  If there is a specified storage pool in the context, create an
+  --  aspect on the package declaration, so that it is used in any
+  --  instance that does not override it.
+
+  if Present (Default_Pool) then
+ declare
+ASN : Node_Id;
+
+ begin
+ASN := Make_Aspect_Specification (Loc,
+   Identifier = Make_Identifier (Loc, Name_Default_Storage_Pool),
+   Expression = New_Copy (Default_Pool));
+
+if No (Aspect_Specifications (Specification (N))) then
+   Set_Aspect_Specifications (Specification (N), New_List (ASN));
+else
+   Append (ASN, Aspect_Specifications (Specification (N)));
+end if;
+ end;
+  end if;
end Analyze_Generic_Package_Declaration;
 

@@ -3605,6 +3626,7 @@
   Act_Tree  : Node_Id;
 
   Gen_Decl : Node_Id;
+  Gen_Spec : Node_Id;
   Gen_Unit : Entity_Id;
 
   Is_Actual_Pack : constant Boolean :=
@@ -3837,6 +3859,7 @@
  end if;
 
  Gen_Decl := Unit_Declaration_Node (Gen_Unit);
+ Gen_Spec := Specification (Gen_Decl);
 
  --  Initialize renamings map, for error checking, and the list that
  --  holds private entities whose views have changed between generic
@@ -3910,6 +3933,52 @@
   New_Copy_List_Tree (Aspect_Specifications (Act_Tree)));
  end if;
 
+ --  The generic may have a generated Default_Storage_Pool aspect,
+ --  set at the point of generic declaration. If the instance has
+ --  that aspect, it overrides the one inherited from the generic.
+
+ if Has_Aspects (Gen_Spec) then
+if No (Aspect_Specifications (N)) then
+   Set_Aspect_Specifications (N,
+ (New_Copy_List_Tree
+   (Aspect_Specifications (Gen_Spec;
+
+else
+   declare
+  ASN1, ASN2 : Node_Id;
+
+   begin
+  ASN1 := First (Aspect_Specifications (N));
+  while Present (ASN1) loop
+ if Chars (Identifier (ASN1))
+= Name_Default_Storage_Pool
+ then
+--  If generic carries a default storage pool, remove
+--  it in favor of the instance one.
+
+ASN2 := First (Aspect_Specifications (Gen_Spec));
+while Present (ASN2) loop
+   if Chars (Identifier (ASN2))
+  = Name_Default_Storage_Pool
+   then
+  Remove (ASN2);
+  exit;
+   end if;
+
+   Next (ASN2);
+end loop;
+ end if;
+
+ Next (ASN1);
+  end loop;
+
+  Prepend_List_To (Aspect_Specifications (N),
+(New_Copy_List_Tree
+  (Aspect_Specifications (Gen_Spec;
+   end;
+end if;
+ end if;
+
  --  Save the instantiation node, for subsequent instantiation of the
  --  body, if there is one and we are generating code for the current
  --  unit. Mark unit as having a body (avoids premature error message).
@@ -4212,6 +4281,40 @@
  if Nkind (Parent (N)) /= 

[Ada] Incorrect RM references on invalid uses of 'Access attribute.

2014-10-31 Thread Arnaud Charlet
The RM reference in the error message for a use of 'access whose prefix is
not aliased mentioned the wrong paragraph in the RM.

Compiling proc.adb must yield:

   proc.adb:6:03:
 object in prefixed call to Q must be aliased (RM 4.1.3 (13 1/2))

--
package P is
  type T is tagged null record;
  procedure Q (Param : access T) is null;
end P;
---
with P;
procedure Proc is
  My_P : P.T;
begin
  My_P.Q;
end Proc;

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Ed Schonberg  schonb...@adacore.com

* sem_attr.adb (Analyze_Access_Attribute): Do not emit error
message if reference does not come from source, as in the case
for the controlling argument of a dispatching call. Error is
diagnosed when call is resolved.
* sem_ch4.adb (Complete_Object_Operation); Fix incorrect RM
reference in error message.
* sem_res.adb (Check_Prefixed_Call): ditto.

Index: sem_res.adb
===
--- sem_res.adb (revision 216960)
+++ sem_res.adb (working copy)
@@ -3261,7 +3261,7 @@
if not Is_Aliased_View (Act) then
   Error_Msg_NE
 (object in prefixed call to must be aliased 
-  (RM-2005 4.3.1 (13)),
+  (RM 4.1.3 (13 1/2)),
 Prefix (Act), Nam);
end if;
 
Index: sem_attr.adb
===
--- sem_attr.adb(revision 216925)
+++ sem_attr.adb(working copy)
@@ -1041,12 +1041,17 @@
  if not Is_Aliased_View (P)
and then not In_Instance
and then not In_Inlined_Body
+   and then Comes_From_Source (N)
  then
 --  Here we have a non-aliased view. This is illegal unless we
 --  have the case of Unrestricted_Access, where for now we allow
 --  this (we will reject later if expected type is access to an
 --  unconstrained array with a thin pointer).
 
+--  No need for an error message on a generated access reference
+--  for the controlling argument in a dispatching call: error will
+--  be reported when resolving the call.
+
 if Aname /= Name_Unrestricted_Access then
Error_Attr_P (prefix of % attribute must be aliased);
Check_No_Implicit_Aliasing (P);
Index: sem_ch4.adb
===
--- sem_ch4.adb (revision 216956)
+++ sem_ch4.adb (working copy)
@@ -7585,7 +7585,7 @@
 if not Is_Aliased_View (Obj) then
Error_Msg_NE
  (object in prefixed call to  must be aliased 
-   (RM-2005 4.3.1 (13)), Prefix (First_Actual), Subprog);
+   (RM 4.1.3 (13 1/2)), Prefix (First_Actual), Subprog);
 end if;
 
 Analyze (First_Actual);


[Ada] Switch -gnatp should have no effect in GNATprove mode

2014-10-31 Thread Arnaud Charlet
In GNATprove mode for formal verification, the presence or absence of
switch -gnatp should have not effect. This was not the case, leading to
missing proofs in GNATprove for overflow/range/division checks when
-gnatp was used. Now fixed.

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Yannick Moy  m...@adacore.com

* gnat1drv.adb (Adjust_Global_Switches): Explicitly mark language
checks as not suppressed in GNATprove mode.

Index: gnat1drv.adb
===
--- gnat1drv.adb(revision 216925)
+++ gnat1drv.adb(working copy)
@@ -363,6 +363,12 @@
  --  happens anyway because this expansion is simply not done in the
  --  SPARK version of the expander.
 
+ --  On the contrary, we need to enable explicitly all language checks,
+ --  as they may have been marked as suppressed by the use of switch
+ --  -gnatp
+
+ Suppress_Options.Suppress := (others = False);
+
  --  Turn off dynamic elaboration checks: generates inconsistencies in
  --  trees between specs compiled as part of a main unit or as part of
  --  a with-clause.


Re: [PATCH x86] Increase PARAM_MAX_COMPLETELY_PEELED_INSNS when branch is costly

2014-10-31 Thread Eric Botcazou
 Agreed, I think the value of 100 was set decade ago by Zdenek and me
 completely artifically. I do not recall any serious tuning of this flag.

Are you talking bout PARAM_MAX_COMPLETELY_PEELED_INSNS here?  If so, see:
  https://gcc.gnu.org/ml/gcc-patches/2012-11/msg01193.html

We have experienced performance regressions because of this arbitrary change 
and bumped it back to 200 unconditionally.

-- 
Eric Botcazou


Minor tweaks in ipa-inline.c

2014-10-31 Thread Eric Botcazou
The usual typo and formatting issues, although there was a novelty since 
want_inline_function_to_all_callers_p used a consistent 3-space indentation.
The function also called twice node-ultimate_alias_target () for no valid 
reasons so the patch cleans that up too.  No functional changes.

Tested on x86_64-suse-linux, applied on mainline as obvious.


2014-10-31  Eric Botcazou  ebotca...@adacore.com

* ipa-inline.c (want_inline_small_function_p): Fix typo and formatting.
(want_inline_function_to_all_callers_p): Fix formatting and simplify.


-- 
Eric BotcazouIndex: ipa-inline.c
===
--- ipa-inline.c	(revision 216950)
+++ ipa-inline.c	(working copy)
@@ -590,19 +590,21 @@ want_inline_small_function_p (struct cgr
   want_inline = false;
 }
   /* Do fast and conservative check if the function can be good
- inline cnadidate.  At themoment we allow inline hints to
- promote non-inline function to inline and we increase
- MAX_INLINE_INSNS_SINGLE 16fold for inline functions.  */
+ inline candidate.  At the moment we allow inline hints to
+ promote non-inline functions to inline and we increase
+ MAX_INLINE_INSNS_SINGLE 16-fold for inline functions.  */
   else if ((!DECL_DECLARED_INLINE_P (callee-decl)
 	(!e-count || !e-maybe_hot_p ()))
-	inline_summary (callee)-min_size - inline_edge_summary (e)-call_stmt_size
+	inline_summary (callee)-min_size
+		- inline_edge_summary (e)-call_stmt_size
 	   MAX (MAX_INLINE_INSNS_SINGLE, MAX_INLINE_INSNS_AUTO))
 {
   e-inline_failed = CIF_MAX_INLINE_INSNS_AUTO_LIMIT;
   want_inline = false;
 }
   else if ((DECL_DECLARED_INLINE_P (callee-decl) || e-count)
-	inline_summary (callee)-min_size - inline_edge_summary (e)-call_stmt_size
+	inline_summary (callee)-min_size
+		- inline_edge_summary (e)-call_stmt_size
 	   16 * MAX_INLINE_INSNS_SINGLE)
 {
   e-inline_failed = (DECL_DECLARED_INLINE_P (callee-decl)
@@ -836,27 +838,26 @@ has_caller_p (struct cgraph_node *node,
 static bool
 want_inline_function_to_all_callers_p (struct cgraph_node *node, bool cold)
 {
-   struct cgraph_node *function = node-ultimate_alias_target ();
-   bool has_hot_call = false;
+  bool has_hot_call = false;
 
-   /* Does it have callers?  */
-   if (!node-call_for_symbol_thunks_and_aliases (has_caller_p, NULL, true))
- return false;
-   /* Already inlined?  */
-   if (function-global.inlined_to)
- return false;
-   if (node-ultimate_alias_target () != node)
- return false;
-   /* Inlining into all callers would increase size?  */
-   if (estimate_growth (node)  0)
- return false;
-   /* All inlines must be possible.  */
-   if (node-call_for_symbol_thunks_and_aliases
- (check_callers, has_hot_call, true))
- return false;
-   if (!cold  !has_hot_call)
- return false;
-   return true;
+  if (node-ultimate_alias_target () != node)
+return false;
+  /* Already inlined?  */
+  if (node-global.inlined_to)
+return false;
+  /* Does it have callers?  */
+  if (!node-call_for_symbol_thunks_and_aliases (has_caller_p, NULL, true))
+return false;
+  /* Inlining into all callers would increase size?  */
+  if (estimate_growth (node)  0)
+return false;
+  /* All inlines must be possible.  */
+  if (node-call_for_symbol_thunks_and_aliases (check_callers, has_hot_call,
+		true))
+return false;
+  if (!cold  !has_hot_call)
+return false;
+  return true;
 }
 
 #define RELATIVE_TIME_BENEFIT_RANGE (INT_MAX / 64)

Re: [RFC, PATCH]: Introduction of callgraph annotation class

2014-10-31 Thread Martin Liška

On 10/16/2014 04:15 PM, Martin Jambor wrote:

Hi,

On Wed, Oct 15, 2014 at 06:26:34PM +0200, Martin Liska wrote:

Hello.

Following patch introduces a new class called callgraph_annotation. Idea behind 
the patch is to provide a generic interface one can use to register custom info 
related to a cgraph_node. As you know, symbol_table provides hooks for 
creation, deletion and duplication of a cgraph_node. If you have a pass, you 
need to handle all these hooks and store custom data in your data structure.

As an example, after discussion with Martin, I chose usage in ipa-prop.h:

data structure:
vecipa_node_params ipa_node_params_vector

if the pass handles an event, following chunk is executed:
if (ipa_node_params_vector.length () = (unsigned) symtab-cgraph_max_uid)
 ipa_node_params_vector.safe_grow_cleared (symtab-cgraph_max_uid + 1);

The problem is that you can have sparse UIDs of cgraph_nodes and every time you 
have to allocate a vector of size equal to cgraph_max_uid.

As a replacement, I implemented first version of cgraph_annotation that internally 
uses hash_mapcgraph_unique_identifier, T.
Every time a node is deleted, we remove corresponding data associated to the 
node.

What do you think about it?


It is clearly an improvement over how we manage our annotations now.
However, I do have a few comments/suggestions:

1. I do not think we need multiple hooks for the same event for one
kind of annotations.  So I think they need not be stored in a
vector.  In fact, I thought that these would be converted to
virtual functions with some default implementation (i.e. nothing
for creation/deletion, memcpy for duplication) and one would only
register the annotation, not its hooks, and redefine the virtual
methods if need be.

2. I think you want to keep a deletion hook (or virtual method),
rather than relying on destructors of types you keep in
annotations.  One reason is that it may be useful to be able to
store a POD and still be notified when its life is over, another is
that once you attempt to store garbage collected data then
destructors really won't make any sense.  Of course it is very nice
if the using destructors also works.

3. If you change a line with struct cgraph_node in ipa-prop.[ch],
don't worry about keeping the struct part and omit it as you do in
other files.  The good old C times are gone forever and I am doing
the same in my patches too.

4. I believe that the reverse map should not be necessary if we change
timing of deletion hook calls which should not cause any problems.

5. I am no C++ expert but can't annotation_hashmap_traits be a private
type of class cgraph_annotation template?

6. I know that an operator overload is a bold proposal but given this
is supposed to be an important part of IPA infrastructure I think
that eventually it would be appropriate and convenient to overload
[] and use that instead of calling get_or_add method.

7. I certainly hope that after we convert all annotations, UID can
become unique and not recycled again and we can use that instead of
the new annotation_uid.  (And use it in dumps too!)

Thanks,

Martin


Thank you Martin for very fitting suggestions, all were implemented
in updated patch.

I've been working on GGC variant of the data structure.

New numbers for ipa_node_params:
cgraph_max_uid = 144720
maximum structures stored in annotation = 64091
# of structures in first IPA pass = 25138

As I replaced vector to annotation, ipa_node_params can save just 6x less 
elements,
giving us about 5MB of memory footprint. Looks negligible, but inlining-related 
structures
will be more interesting. I've been working on a variant that can be used with 
GGC structures.

What do you think about merging the patch for 5.0?

Thank you,
Martin






Thank you,
Martin



diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 04ce0c0..bf34c96 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1171,6 +1171,7 @@ OBJS = \
cfgrtl.o \
symtab.o \
cgraph.o \
+   annotation.o \
cgraphbuild.o \
cgraphunit.o \
cgraphclones.o \
diff --git a/gcc/annotation.c b/gcc/annotation.c
new file mode 100644
index 000..a8b6053
--- /dev/null
+++ b/gcc/annotation.c
@@ -0,0 +1 @@
+#include annotation.h
diff --git a/gcc/annotation.h b/gcc/annotation.h
new file mode 100644
index 000..7520677
--- /dev/null
+++ b/gcc/annotation.h
@@ -0,0 +1,285 @@
+/* Annotations handling code.
+   Copyright (C) 2014 Free Software Foundation, Inc.
+   Contributed by Martin Liska
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of 

[PATCH] Merge from match-and-simplify, remove fold_unary dispatch from fold_stmt

2014-10-31 Thread Richard Biener
This implements the last pattern from fold_unary that covers
inputs that can come from a GIMPLE_UNARY_RHS assignment
and thus allows removal of the fold_unary dispatch from fold_stmt
and gimple_fold_stmt_to_constant_1.  Remember that to not cause
regressions it is enough to cover cases that do not need SSA
name use-def following.  Also remember that gimple_simplify
still dispatches to fold_unary for all tcc_constant operands.

The next goal is obviously to remove the GIMPLE_BINARY_RHS and
GIMPLE_TERNARY_RHS dispatches to fold_binary/ternary.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2014-10-31  Richard Biener  rguent...@suse.de

* match.pd: Add two abs patterns.  Announce tree_expr_nonnegative_p.
* fold-const.c (fold_unary_loc): Remove them here.
(tree_unary_nonnegative_warnv_p): Use CASE_CONVERT.
* gimple-fold.c (fold_gimple_assign): Remove now obsolete
GIMPLE_UNARY_RHS case.
(gimple_fold_stmt_to_constant_1): Likewise.


mas-merge-10
Description: Binary data


[Ada] Store the display name in the project node

2014-10-31 Thread Arnaud Charlet
The Display_Name of a project is now store in its project node instead
of a hash table. No change of functionality.

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-10-31  Vincent Celier  cel...@adacore.com

* prj-part.adb (Parse_Single_Project): Call Set_Display_Name_Of.
* prj-proc.adb (Recursive_Process): Call Display_Name_Of to
get the project Display_Name.
* prj-tree.adb (Display_Name_Of): New function
(Set_Display_Name_Of): New procedure.
(Create_Project): Call Set_Display_Name_Of.
* prj-tree.ads (Display_Name_Of): New function.
(Set_Display_Name_Of): New procedure.
(Project_Node_Record): New component Display_Name.
(Project_Name_And_Node): Remove component Display_Name.

Index: prj-proc.adb
===
--- prj-proc.adb(revision 216970)
+++ prj-proc.adb(working copy)
@@ -2765,6 +2765,10 @@
 Success := not Prj.Tree.No (Loaded_Project);
 
 if Success then
+   if Node_Tree.Incomplete_With then
+  From_Project_Node_Tree.Incomplete_With := True;
+   end if;
+
List.Tree := new Project_Tree_Data (Is_Root_Tree = False);
Prj.Initialize (List.Tree);
List.Tree.Shared := In_Tree.Shared;
@@ -2928,9 +2932,9 @@
 Name : constant Name_Id :=
  Name_Of (From_Project_Node, From_Project_Node_Tree);
 
-Name_Node : constant Tree_Private_Part.Project_Name_And_Node :=
-  Tree_Private_Part.Projects_Htable.Get
-(From_Project_Node_Tree.Projects_HT, Name);
+Display_Name : constant Name_Id :=
+ Display_Name_Of
+   (From_Project_Node, From_Project_Node_Tree);
 
  begin
 Project := Processed_Projects.Get (Name);
@@ -2994,15 +2998,8 @@
 Processed_Projects.Set (Name, Project);
 
 Project.Name := Name;
+Project.Display_Name := Display_Name;
 
---  Make sure that the project display name is never No_Name
-
-if Name_Node.Display_Name = No_Name then
-   Project.Display_Name := Name;
-else
-   Project.Display_Name := Name_Node.Display_Name;
-end if;
-
 Get_Name_String (Name);
 
 --  If name starts with the virtual prefix, flag the project as
Index: prj-part.adb
===
--- prj-part.adb(revision 216965)
+++ prj-part.adb(working copy)
@@ -1298,7 +1298,6 @@
   Name_From_Path  : constant Name_Id :=
 Project_Name_From (Path_Name, Is_Config_File = Is_Config_File);
   Name_Of_Project : Name_Id := No_Name;
-  Display_Name_Of_Project : Name_Id := No_Name;
 
   Duplicated : Boolean := False;
 
@@ -1634,11 +1633,11 @@
 end if;
  end;
 
- --  Read the original casing of the project name
+ --  Read the original casing of the project name and put it in the
+ --  project node.
 
  declare
 Loc : Source_Ptr;
-
  begin
 Loc := Location_Of (Project, In_Tree);
 for J in 1 .. Name_Len loop
@@ -1646,7 +1645,7 @@
Loc := Loc + 1;
 end loop;
 
-Display_Name_Of_Project := Name_Find;
+Set_Display_Name_Of (Project, In_Tree, Name_Find);
  end;
 
  declare
@@ -2018,7 +2017,6 @@
(T = In_Tree.Projects_HT,
 K = Name_Of_Project,
 E = (Name   = Name_Of_Project,
-  Display_Name   = Display_Name_Of_Project,
   Node   = Project,
   Resolved_Path  = Resolved_Path_Name,
   Extended   = Extended,
Index: prj-tree.adb
===
--- prj-tree.adb(revision 216925)
+++ prj-tree.adb(working copy)
@@ -110,26 +110,27 @@
  Project_Node_Table.Increment_Last (In_Tree.Project_Nodes);
  In_Tree.Project_Nodes.Table
(Project_Node_Table.Last (In_Tree.Project_Nodes)) :=
-   (Kind  = N_Comment_Zones,
-Qualifier = Unspecified,
-Expr_Kind = Undefined,
-Location  = No_Location,
-Directory = No_Path,
-Variables = Empty_Node,
-Packages  = Empty_Node,
-Pkg_Id= Empty_Package,
-Name  = No_Name,
-Src_Index = 0,
-Path_Name = No_Path,
-Value = No_Name,
-Default   = Empty_Value,
-Field1= Empty_Node,
-Field2= Empty_Node,
-Field3= Empty_Node,
-Field4= Empty_Node,
-Flag1 = False,
-Flag2 = False,
-   

Re: [PATCH][AArch64][4.8] LINK_SPEC changes for Cortex-A53 erratum 835769 workaround

2014-10-31 Thread Kyrill Tkachov


On 22/10/14 15:20, Kyrill Tkachov wrote:

Hi all,

This is the 4.8 backport of the LINK_SPEC changes to pass down the
linker option
--fix-cortex-a53-835769

Bootstrapped and tested on aarch64-none-linux-gnu.
This depends on the patches under review at:
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01757.html
and
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01758.html

Ok for that branch after the prerequisites go in?


Ping.
I've committed the 4.9 version of this to that branch.

Thanks,
Kyrill



Thanks,
Kyrill

2014-10-22  Kyrylo Tkachov  kyrylo.tkac...@arm.com

  * config/aarch64/aarch64-elf-raw.h (CA53_ERR_835769_SPEC): Define.
  (LINK_SPEC): Include CA53_ERR_835769_SPEC.
  * config/aarch64/aarch64-linux.h (CA53_ERR_835769_SPEC): Define.
  (LINK_SPEC): Include CA53_ERR_835769_SPEC.





[PATCH][AARCH64]Add ACLE arch-related predefined macros

2014-10-31 Thread Renlin Li

Hi all,

This is a simple patch to add arch-related macros defined ACLE 2.0.

aarch64-none-elf target is tested on the model, no new issues.

Is this Okay for trunk?

gcc/ChangeLog:

2014-10-31  Renlin Li  renlin...@arm.com

* config/aarch64/aarch64.c (aarch64_architecture_version): New.
(processor): New architecture_version field.
(aarch64_override_options): Initialize aarch64_architecture_version.
* config/aarch64/aarch64.h (TARGET_CPU_CPP_BUILTINS): Define 
__ARM_ARCH,

__ARM_ARCH_PROFILE, aarch64_arch_name macro.
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index b94f450..5af4e14 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -145,6 +145,9 @@ static bool aarch64_vectorize_vec_perm_const_ok (enum machine_mode vmode,
 		 const unsigned char *sel);
 static int aarch64_address_cost (rtx, enum machine_mode, addr_space_t, bool);
 
+/* Major revision number of the ARM Architecture implemented by the target.  */
+unsigned aarch64_architecture_version;
+
 /* The processor for which instructions should be scheduled.  */
 enum aarch64_processor aarch64_tune = cortexa53;
 
@@ -339,6 +342,7 @@ struct processor
   const char *const name;
   enum aarch64_processor core;
   const char *arch;
+  unsigned architecture_version;
   const unsigned long flags;
   const struct tune_params *const tune;
 };
@@ -347,21 +351,23 @@ struct processor
 static const struct processor all_cores[] =
 {
 #define AARCH64_CORE(NAME, X, IDENT, ARCH, FLAGS, COSTS) \
-  {NAME, IDENT, #ARCH, FLAGS | AARCH64_FL_FOR_ARCH##ARCH, COSTS##_tunings},
+  {NAME, IDENT, #ARCH, ARCH,\
+FLAGS | AARCH64_FL_FOR_ARCH##ARCH, COSTS##_tunings},
 #include aarch64-cores.def
 #undef AARCH64_CORE
-  {generic, cortexa53, 8, AARCH64_FL_FPSIMD | AARCH64_FL_FOR_ARCH8, generic_tunings},
-  {NULL, aarch64_none, NULL, 0, NULL}
+  {generic, cortexa53, 8, 8,\
+AARCH64_FL_FPSIMD | AARCH64_FL_FOR_ARCH8, generic_tunings},
+  {NULL, aarch64_none, NULL, 0, 0, NULL}
 };
 
 /* Architectures implementing AArch64.  */
 static const struct processor all_architectures[] =
 {
 #define AARCH64_ARCH(NAME, CORE, ARCH, FLAGS) \
-  {NAME, CORE, #ARCH, FLAGS, NULL},
+  {NAME, CORE, #ARCH, ARCH, FLAGS, NULL},
 #include aarch64-arches.def
 #undef AARCH64_ARCH
-  {NULL, aarch64_none, NULL, 0, NULL}
+  {NULL, aarch64_none, NULL, 0, 0, NULL}
 };
 
 /* Target specification.  These are populated as commandline arguments
@@ -6449,6 +6455,7 @@ aarch64_override_options (void)
   aarch64_tune_flags = selected_tune-flags;
   aarch64_tune = selected_tune-core;
   aarch64_tune_params = selected_tune-tune;
+  aarch64_architecture_version = selected_cpu-architecture_version;
 
   if (aarch64_fix_a53_err835769 == 2)
 {
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 11aa10b..ed38b85 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -28,7 +28,13 @@
 {			\
   builtin_define (__aarch64__);   \
   builtin_define (__ARM_64BIT_STATE); \
+  builtin_define_with_int_value \
+(__ARM_ARCH, aarch64_architecture_version);   \
+  cpp_define_formatted  \
+(parse_in, __ARM_ARCH_%dA, aarch64_architecture_version); \
   builtin_define (__ARM_ARCH_ISA_A64);\
+  builtin_define_with_int_value \
+(__ARM_ARCH_PROFILE, 'A');\
   builtin_define (__ARM_FEATURE_CLZ); \
   builtin_define (__ARM_FEATURE_IDIV);\
   builtin_define (__ARM_FEATURE_UNALIGNED);   \
@@ -172,6 +178,8 @@
 
 #define PCC_BITFIELD_TYPE_MATTERS	1
 
+/* Major revision number of the ARM Architecture implemented by the target.  */
+extern unsigned aarch64_architecture_version;
 
 /* Instruction tuning/selection flags.  */
 

[PATCH][AARCH64]Fix PR63424 by adding sumaxminv2di3 pattern

2014-10-31 Thread Renlin Li

Hi all,

This is a patch which will fix PR63424.

It implements signed/unsigned max/min pattern for V2DI mode in terms of 
vcondv2div2di pattern.


In this particular case, VEC_COND_EXPR (V2DImode) is generated as 
aarch64 target supports it (vcondmodemode for VALL). The 
VEC_COND_EXPR will further folded into MIN_EXPR/MAX_EXPR in dom pass 
unconditionally. Later in expand pass, the compiler tries to expand 
min_expr using standard RTL operation. It fails, because aarch64 target 
don't have minv2di3 pattern implemented. It then tries to generate 
conditional move and comparebranch sequence, all fails. At last it 
falls into libfunc call, no luck either. An ICE to complain about this.


aarch64-none-elf toolchain has been tested on the model, no regressions.

Is it Okay for trunk?

gcc/ChangeLog:

2014-10-31  Renlin Li  renlin...@arm.com
PR target/63424
* config/aarch64/aarch64-simd.md (sumaxminv2di3): New.

gcc/testsuite/ChangeLog:

2014-10-31  Renlin Li  renlin...@arm.com
PR target/63424
* gcc.target/aarch64/pr63424.c: New.From 3bfb5960ffd4e0606fb02cf553cd5dcd45340810 Mon Sep 17 00:00:00 2001
From: Renlin Li renlin...@arm.com
Date: Wed, 29 Oct 2014 09:35:25 +
Subject: [PATCH 1/2] fix PR63424

---
 gcc/config/aarch64/aarch64-simd.md |   35 +
 gcc/testsuite/gcc.target/aarch64/pr63424.c |   39 
 2 files changed, 74 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/pr63424.c

diff --git a/gcc/config/aarch64/aarch64-simd.md b/gcc/config/aarch64/aarch64-simd.md
index cab26a3..41ddbb4 100644
--- a/gcc/config/aarch64/aarch64-simd.md
+++ b/gcc/config/aarch64/aarch64-simd.md
@@ -951,6 +951,41 @@
   [(set_attr type neon_minmaxq)]
 )
 
+(define_expand sumaxminv2di3
+  [(parallel [
+(set (match_operand:V2DI 0 register_operand )
+	 (MAXMIN:V2DI (match_operand:V2DI 1 register_operand )
+		  (match_operand:V2DI 2 register_operand )))
+(clobber (reg:CC CC_REGNUM))])]
+  TARGET_SIMD
+{
+  enum rtx_code cmp_operator;
+  rtx cmp_fmt;
+
+  switch (CODE)
+{
+case UMIN:
+  cmp_operator = LTU;
+  break;
+case SMIN:
+  cmp_operator = LT;
+  break;
+case UMAX:
+  cmp_operator = GTU;
+  break;
+case SMAX:
+  cmp_operator = GT;
+  break;
+default:
+  gcc_unreachable ();
+}
+
+  cmp_fmt = gen_rtx_fmt_ee (cmp_operator, V2DImode, operands[1], operands[2]);
+  emit_insn (gen_aarch64_vcond_internalv2div2di (operands[0], operands[1],
+  operands[2], cmp_fmt, operands[1], operands[2]));
+  DONE;
+})
+
 ;; vec_concat gives a new vector with the low elements from operand 1, and
 ;; the high elements from operand 2.  That is to say, given op1 = { a, b }
 ;; op2 = { c, d }, vec_concat (op1, op2) = { a, b, c, d }.
diff --git a/gcc/testsuite/gcc.target/aarch64/pr63424.c b/gcc/testsuite/gcc.target/aarch64/pr63424.c
new file mode 100644
index 000..c6bd762
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr63424.c
@@ -0,0 +1,39 @@
+/* { dg-do compile } */
+/* { dg-options -O3 } */
+
+#include stdint.h
+
+uint32_t
+truncate_int (const unsigned long long value)
+{
+  if ( value  0 )
+{
+  return 0;
+}
+  else if ( value  UINT32_MAX )
+{
+  return UINT32_MAX;
+}
+  else
+return (uint32_t)value;
+}
+
+uint32_t
+mul (const unsigned long long x, const unsigned long long y)
+{
+  uint32_t value = truncate_int (x * y);
+  return value;
+}
+
+uint32_t *
+test(unsigned size, uint32_t *a, uint32_t s)
+{
+  unsigned i;
+
+  for (i = 0; i  size; i++)
+{
+  a[i] = mul (a[i], s);
+}
+
+  return a;
+}
-- 
1.7.9.5


Re: [PATCH, ifcvt] Check size cost in noce_try_store_flag_mask

2014-10-31 Thread pinskia




 On Oct 31, 2014, at 4:07 AM, Matthew Fortune matthew.fort...@imgtec.com 
 wrote:
 
 Andrew Pinski pins...@gmail.com writes:
 On Thu, Oct 30, 2014 at 11:30 PM, Zhenqiang Chen zhenqiang.c...@arm.com
 wrote:
 Thank you all for the comments. Patch is updated.
 
 Bootstrap and no make check regression on X86-64.
 No make check regression with Cortex-M0 qemu.
 No performance changes for coremark, dhrystone, spec2000 and spec2006 on
 X86-64 and Cortex-A15.
 
 For CSiBE, ARM Cortex-M0 result is a little better. A little regression
 for
 MIPS (less than 0.01%).
 
 I think I have a fix for MIPS which I need to submit too.  The problem
 is IF_THEN_ELSE is not implemented for mips_rtx_costs.
 
 Something like the attached one (though It is not updated for the new
 cores including octeon3).
 
 This looks OK in principle so I have no objection to the original patch
 from Zhengiang. The MIPS patch can follow on.
 
 Andrew: Are you setting higher costs for octeon to try and avoid the
 conversion owing to high latency for MOV[NZ] etc in octeon*?

Yes. In fact I was doing it for the higher latency on octeon 2 than Octeon 1/+. 
I saw a small improvement with that, using other instructions in one or two 
cases which be scheduled with other code. 


 Should that
 be conditional on speed vs size?

Yes though I thought we had a variable for size too. 

Thanks,
Andrew

 
 Thanks,
 Matthew


[Patch 1/7] Hookize *_BY_PIECES_P

2014-10-31 Thread James Greenhalgh

Hi,

This patch prepares for removing all the *BY_PIECES_P macros by
introducing a new target hook TARGET_USE_BY_PIECES_INFRASTRUCTURE_P.

Tested on ARM/AArch64/x86_64 with no issues.

Ok for trunk?

Thanks,
James

---
gcc/

2014-10-31  James Greenhalgh  james.greenha...@arm.com

* target.def (use_by_pieces_infrastructure_p): New.
* doc/tm.texi.in (MOVE_BY_PIECES_P): Describe that this macro
is deprecated.
(STORE_BY_PIECES_P): Likewise.
(CLEAR_BY_PIECES_P): Likewise.
(SET_BY_PIECES_P): Likewise.
(TARGET_MOVE_BY_PIECES_PROFITABLE_P): Add hook.
* doc/tm.texi: Regenerate.
* expr.c (MOVE_BY_PIECES_P): Rewrite in terms of
TARGET_USE_BY_PIECES_INFRASTRUCTURE_P.
(STORE_BY_PIECES_P): Likewise.
(CLEAR_BY_PIECES_P): Likewise.
(SET_BY_PIECES_P): Likewise.
(STORE_MAX_PIECES): Move to...
* defaults.h (STORE_MAX_PIECES): ...here.
* targhooks.c (get_move_ratio): New.
(default_use_by_pieces_infrastructure_p): Likewise.
* targhooks.h (default_use_by_pieces_infrastructure_p): New.
* target.h (by_pieces_operation): New.
diff --git a/gcc/defaults.h b/gcc/defaults.h
index c1776b0..d2609e7 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -1006,6 +1006,15 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define MOVE_MAX_PIECES   MOVE_MAX
 #endif
 
+/* STORE_MAX_PIECES is the number of bytes at a time that we can
+   store efficiently.  Due to internal GCC limitations, this is
+   MOVE_MAX_PIECES limited by the number of bytes GCC can represent
+   for an immediate constant.  */
+
+#ifndef STORE_MAX_PIECES
+#define STORE_MAX_PIECES  MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
+#endif
+
 #ifndef MAX_MOVE_MAX
 #define MAX_MOVE_MAX MOVE_MAX
 #endif
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index bb04401..cfb8388 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -6128,8 +6128,45 @@ A C expression used to determine whether @code{move_by_pieces} will be used to
 copy a chunk of memory, or whether some other block move mechanism
 will be used.  Defaults to 1 if @code{move_by_pieces_ninsns} returns less
 than @code{MOVE_RATIO}.
+
+This macro is deprecated.  New ports should implement
+@code{TARGET_USE_BY_PIECES_INFRASTRUCTURE_P} instead.
 @end defmac
 
+@deftypefn {Target Hook} bool TARGET_USE_BY_PIECES_INFRASTRUCTURE_P (unsigned int @var{size}, unsigned int @var{alignment}, enum by_pieces_operation @var{op}, bool @var{speed_p})
+GCC will attempt several strategies when asked to copy between
+two areas of memory, or to set, clear or store to memory, for example
+when copying a @code{struct}. The @code{by_pieces} infrastructure
+implements such memory operations as a sequence of load, store or move
+insns.  Alternate strategies are to expand the
+@code{movmem} or @code{setmem} optabs, to emit a library call, or to emit
+unit-by-unit, loop-based operations.
+
+This target hook should return true if, for a memory operation with a
+given @var{size} and @var{alignment}, using the @code{by_pieces}
+infrastructure is expected to result in better code generation.
+Both @var{size} and @var{alignment} are measured in terms of storage
+units.
+
+The parameter @var{op} is one of: @code{CLEAR_BY_PIECES},
+@code{MOVE_BY_PIECES}, @code{SET_BY_PIECES}, @code{STORE_BY_PIECES}.
+These describe the type of memory operation under consideration.
+
+The parameter @var{speed_p} is true if the code is currently being
+optimized for speed rather than size.
+
+Returning true for higher values of @var{size} can improve code generation
+for speed if the target does not provide an implementation of the
+@code{movmem} or @code{setmem} standard names, if the @code{movmem} or
+@code{setmem} implementation would be more expensive than a sequence of
+insns, or if the overhead of a library call would dominate that of
+the body of the memory operation.
+
+Returning true for higher values of @code{size} may also cause an increase
+in code size, for example where the number of insns emitted to perform a
+move would be greater than that of a library call.
+@end deftypefn
+
 @defmac MOVE_MAX_PIECES
 A C expression used by @code{move_by_pieces} to determine the largest unit
 a load or store used to copy memory is.  Defaults to @code{MOVE_MAX}.
@@ -6152,6 +6189,9 @@ A C expression used to determine whether @code{clear_by_pieces} will be used
 to clear a chunk of memory, or whether some other block clear mechanism
 will be used.  Defaults to 1 if @code{move_by_pieces_ninsns} returns less
 than @code{CLEAR_RATIO}.
+
+This macro is deprecated.  New ports should implement
+@code{TARGET_USE_BY_PIECES_INFRASTRUCTURE_P} instead.
 @end defmac
 
 @defmac SET_RATIO (@var{speed})
@@ -6174,6 +6214,9 @@ other mechanism will be used.  Used by @code{__builtin_memset} when
 storing values other than constant zero.
 Defaults to 1 if @code{move_by_pieces_ninsns} returns less
 than @code{SET_RATIO}.
+

RE: [Patch 1/6] Hookize MOVE_BY_PIECES_P, remove most uses of MOVE_RATIO

2014-10-31 Thread James Greenhalgh
On Wed, Oct 29, 2014 at 03:31:54PM +, James Greenhalgh wrote:
 On Wed, Oct 29, 2014 at 11:42:06AM +, Matthew Fortune wrote:
  Hi James,
  
  I think you have a bug in the following hunk where you pass
  STORE_MAX_PIECES in place of the optimise for speed flag. I guess you
  would need an extra argument to pass a different *_MAX_PIECES value
  in.
 
 Yup, good spot and agreed. I think I'll respin this series and get rid of all
 the *_BY_PIECES_P in one sweep. I'm thinking of something like:
 
 use_by_pieces_infrastructure_p (unsigned int size,
   unsigned int alignment,
   enum by_pieces_mode mode,
   bool speed_p)
 
 which will take the type of by_pieces operation as the third parameter.

...and that patch series would look something like this.

We hookize all of CLEAR_BY_PIECES_P, MOVE_BY_PIECES_P, SET_BY_PIECES_P
and STORE_BY_PIECES_P behind one target hook:
TARGET_USE_BY_PIECES_INFRASTRUCTURE_P.

We then clean up each of the targets who use these macros, and finally
delete the macros entirely and poison them.

Jeff, thanks for reviewing the previous patch set, unfortunately finishing
the job off properly costs a little extra for each target, so I guess I'll
need a new set of review. Sorry about that.

The series looks like this:

[Patch 1/7] Hookize *_BY_PIECES_P
[Patch 2/7 s390] Deprecate *_BY_PIECES_P, move to hookized version
[Patch 3/7 arc] Deprecate *_BY_PIECES_P, move to hookized version
[Patch 4/7 sh] Deprecate *_BY_PIECES_P, move to hookized version
[Patch 5/7 mips] Deprecate *_BY_PIECES_P, move to hookized version
[Patch 6/7 AArch64] Deprecate *_BY_PIECES_P, move to hookized version
[Patch 7/7] Remove *_BY_PIECES_P

I've bootstrapped and tested the full patch series on x86_64, ARM and
AArch64, and as before I've successfully built toolchains for the
other architectures (except arc, which I've struggled to build a binutils
for).

OK?

Thanks,
James

[Patch 2/7 s390] Deprecate *_BY_PIECES_P, move to hookized version

2014-10-31 Thread James Greenhalgh

Hi,

This patch moves s390 to TARGET_USE_BY_PIECES_INFRASTRUCTURE_P.

It looks to me that s390 wires all the hooks in this set to the
same return value, so that is what I've implemented.

I tried building a compiler and there were no fires, but otherwise,
I have no reasonable way to test this patch. If one of the s390
maintainers wants to pick it up and test it, that would be much
appreciated.

Ok?

James

---
2014-10-31  James Greenhalgh  james.greenha...@arm.com

* config/s390/s390.c (s390_use_by_pieces_infrastructure_p): New.
(TARGET_USE_BY_PIECES_INFRASTRUCTURE_P): Likewise.
* config/s390/s390.h (MOVE_BY_PIECES_P): Remove.
(CLEAR_BY_PIECES): Likewise.
(SET_BY_PIECES): Likewise.
(STORE_BY_PIECES): Likewise.
diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 874eb7c..51ae90c 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -12032,6 +12032,18 @@ s390_option_override (void)
   register_pass (insert_pass_s390_early_mach);
 }
 
+/* Implement TARGET_USE_BY_PIECES_INFRASTRUCTURE_P.  */
+
+static bool
+s390_use_by_pieces_infrastructure_p (unsigned int size,
+ unsigned int align ATTRIBUTE_UNUSED,
+ enum by_pieces_operation op ATTRIBUTE_UNUSED,
+ bool speed_p ATTRIBUTE_UNUSED)
+{
+  return (size == 1 || size == 2
+	  || size == 4 || (TARGET_ZARCH  size == 8));
+}
+
 /* Initialize GCC target structure.  */
 
 #undef  TARGET_ASM_ALIGNED_HI_OP
@@ -12217,6 +12229,10 @@ s390_option_override (void)
 #undef TARGET_SET_UP_BY_PROLOGUE
 #define TARGET_SET_UP_BY_PROLOGUE s300_set_up_by_prologue
 
+#undef TARGET_USE_BY_PIECES_INFRASTRUCTURE_P
+#define TARGET_USE_BY_PIECES_INFRASTRUCTURE_P \
+  s390_use_by_pieces_infrastructure_p
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include gt-s390.h
diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h
index 0a935ee..d933b8d 100644
--- a/gcc/config/s390/s390.h
+++ b/gcc/config/s390/s390.h
@@ -744,24 +744,6 @@ do {	\
 #define MOVE_MAX_PIECES (TARGET_ZARCH ? 8 : 4)
 #define MAX_MOVE_MAX 16
 
-/* Determine whether to use move_by_pieces or block move insn.  */
-#define MOVE_BY_PIECES_P(SIZE, ALIGN)		\
-  ( (SIZE) == 1 || (SIZE) == 2 || (SIZE) == 4	\
-|| (TARGET_ZARCH  (SIZE) == 8) )
-
-/* Determine whether to use clear_by_pieces or block clear insn.  */
-#define CLEAR_BY_PIECES_P(SIZE, ALIGN)		\
-  ( (SIZE) == 1 || (SIZE) == 2 || (SIZE) == 4	\
-|| (TARGET_ZARCH  (SIZE) == 8) )
-
-/* This macro is used to determine whether store_by_pieces should be
-   called to memcpy storage when the source is a constant string.  */
-#define STORE_BY_PIECES_P(SIZE, ALIGN) MOVE_BY_PIECES_P (SIZE, ALIGN)
-
-/* Likewise to decide whether to memset storage with byte values
-   other than zero.  */
-#define SET_BY_PIECES_P(SIZE, ALIGN) STORE_BY_PIECES_P (SIZE, ALIGN)
-
 /* Don't perform CSE on function addresses.  */
 #define NO_FUNCTION_CSE
 

[Patch 4/7 sh] Deprecate *_BY_PIECES_P, move to hookized version

2014-10-31 Thread James Greenhalgh

Hi,

This patch moves sh to TARGET_USE_BY_PIECES_INFRASTRUCTURE_P.

For sh, STORE_BY_PIECES and SET_BY_PIECES share an implementation,
MOVE_BY_PIECES is different. Implement as so, and use the default
implementation for CLEAR_BY_PIECES.

I tried building a compiler and there were no fires, but otherwise,
I have no reasonable way to test this patch. If one of the sh
maintainers wants to pick it up and test it, that would be much
appreciated.

Thanks,
James

---
gcc/

2014-10-31  James Greenhalgh  james.greenha...@arm.com

* config/sh/sh.c (TARGET_USE_BY_PIECES_INFRASTRUCTURE_P): New.
(sh_use_by_pieces_infrastructure_p): Likewise.
* config/sh/sh.h (MOVE_BY_PIECES_P): Remove.
(STORE_BY_PIECES_P): Likewise.
(SET_BY_PIECES_P): Likewise.
diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index 1dc1bf4..3bbbd23 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -338,6 +338,10 @@ static void sh_conditional_register_usage (void);
 static bool sh_legitimate_constant_p (machine_mode, rtx);
 static int mov_insn_size (machine_mode, bool);
 static int mov_insn_alignment_mask (machine_mode, bool);
+static bool sh_use_by_pieces_infrastructure_p (unsigned int,
+	   unsigned int,
+	   enum by_pieces_operation,
+	   bool);
 static bool sequence_insn_p (rtx_insn *);
 static void sh_canonicalize_comparison (int *, rtx *, rtx *, bool);
 static void sh_canonicalize_comparison (enum rtx_code, rtx, rtx,
@@ -640,6 +644,10 @@ static const struct attribute_spec sh_attribute_table[] =
 #undef TARGET_FIXED_CONDITION_CODE_REGS
 #define TARGET_FIXED_CONDITION_CODE_REGS sh_fixed_condition_code_regs
 
+#undef TARGET_USE_BY_PIECES_INFRASTRUCTURE_P
+#define TARGET_USE_BY_PIECES_INFRASTRUCTURE_P \
+  sh_use_by_pieces_infrastructure_p
+
 /* Machine-specific symbol_ref flags.  */
 #define SYMBOL_FLAG_FUNCVEC_FUNCTION	(SYMBOL_FLAG_MACH_DEP  0)
 
@@ -13674,4 +13682,27 @@ sh_mode_priority (int entity ATTRIBUTE_UNUSED, int n)
   return ((TARGET_FPU_SINGLE != 0) ^ (n) ? FP_MODE_SINGLE : FP_MODE_DOUBLE);
 }
 
+/* Implement TARGET_USE_BY_PIECES_INFRASTRUCTURE_P.  */
+
+static bool
+sh_use_by_pieces_infrastructure_p (unsigned int size,
+   unsigned int align,
+   enum by_pieces_operation op,
+   bool speed_p)
+{
+  switch (op)
+{
+  case MOVE_BY_PIECES:
+	return move_by_pieces_ninsns (size, align, MOVE_MAX_PIECES + 1)
+	   (!speed_p ? 2 : (align = 32) ? 16 : 2);
+  case STORE_BY_PIECES:
+  case SET_BY_PIECES:
+	return move_by_pieces_ninsns (size, align, STORE_MAX_PIECES + 1)
+	   (!speed_p ? 2 : (align = 32) ? 16 : 2);
+  default:
+	return default_use_by_pieces_infrastructure_p (size, align,
+		   op, speed_p);
+}
+}
+
 #include gt-sh.h
diff --git a/gcc/config/sh/sh.h b/gcc/config/sh/sh.h
index 5b8b4a1..92835d7 100644
--- a/gcc/config/sh/sh.h
+++ b/gcc/config/sh/sh.h
@@ -1591,16 +1591,6 @@ struct sh_args {
 #define USE_STORE_PRE_DECREMENT(mode)((mode == SImode || mode == DImode) \
 	  ? 0 : TARGET_SH1)
 
-#define MOVE_BY_PIECES_P(SIZE, ALIGN) \
-  (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
-(optimize_size ? 2 : ((ALIGN = 32) ? 16 : 2)))
-
-#define STORE_BY_PIECES_P(SIZE, ALIGN) \
-  (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
-(optimize_size ? 2 : ((ALIGN = 32) ? 16 : 2)))
-
-#define SET_BY_PIECES_P(SIZE, ALIGN) STORE_BY_PIECES_P(SIZE, ALIGN)
-
 /* If a memory clear move would take CLEAR_RATIO or more simple
move-instruction pairs, we will do a setmem instead.  */
 

[Patch 3/7 arc] Deprecate *_BY_PIECES_P, move to hookized version

2014-10-31 Thread James Greenhalgh

Hi,

This patch moves arc to TARGET_USE_BY_PIECES_INFRASTRUCTURE_P.

While I am there, arc defines a macro CAN_MOVE_BY_PIECES, which is
unused, so clean that up too.

arc only implements MOVE_BY_PIECES_P, wiring it to false. Mirror that
behaviour, and use the default hook for other by_pieces operations.

I tried building a compiler but no amount of fiddling with target
strings got me to a sensible result, so this patch is completely
untested.

If one of the arc maintainers could give it a spin that would be
helpful.

OK?

Thanks,
James

 ---
2014-10-31  James Greenhalgh  james.greenha...@arm.com

* config/arc/arc.c (TARGET_USE_BY_PIECES_INFRASTRUCTURE_P): New.
(arc_use_by_pieces_infrastructure_p): Likewise.
* confir/arc/arc.h (MOVE_BY_PIECES_P): Delete.
(CAN_MOVE_BY_PIECES): Likewise.
diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index d04be01..c5b8b80 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -415,6 +415,11 @@ static void output_short_suffix (FILE *file);
 
 static bool arc_frame_pointer_required (void);
 
+static bool arc_use_by_pieces_infrastructure_p (unsigned int,
+		unsigned int,
+		enum by_pieces_operation op,
+		bool);
+
 /* Implements target hook vector_mode_supported_p.  */
 
 static bool
@@ -530,6 +535,10 @@ static void arc_finalize_pic (void);
 #undef TARGET_DELEGITIMIZE_ADDRESS
 #define TARGET_DELEGITIMIZE_ADDRESS arc_delegitimize_address
 
+#undef TARGET_USE_BY_PIECES_INFRASTRUCTURE_P
+#define TARGET_USE_BY_PIECES_INFRASTRUCTURE_P \
+  arc_use_by_pieces_infrastructure_p
+
 /* Usually, we will be able to scale anchor offsets.
When this fails, we want LEGITIMIZE_ADDRESS to kick in.  */
 #undef TARGET_MIN_ANCHOR_OFFSET
@@ -9383,6 +9392,21 @@ arc_legitimize_reload_address (rtx *p, machine_mode mode, int opnum,
   return false;
 }
 
+/* Implement TARGET_USE_BY_PIECES_INFRASTRUCTURE_P.  */
+
+static bool
+arc_use_by_pieces_infrastructure_p (unsigned int size,
+unsigned int align,
+enum by_pieces_operation op,
+bool speed_p)
+{
+  /* Let the movmem expander handle small block moves.  */
+  if (op == MOVE_BY_PIECES_P)
+return false;
+
+  return default_use_by_pieces_infrastructure_p (size, align, op, speed_p);
+}
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include gt-arc.h
diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
index d40f5c3..2d27787 100644
--- a/gcc/config/arc/arc.h
+++ b/gcc/config/arc/arc.h
@@ -1553,12 +1553,6 @@ extern int arc_return_address_regs[4];
in one reasonably fast instruction.  */
 #define MOVE_MAX 4
 
-/* Let the movmem expander handle small block moves.  */
-#define MOVE_BY_PIECES_P(LEN, ALIGN)  0
-#define CAN_MOVE_BY_PIECES(SIZE, ALIGN) \
-  (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
-(unsigned int) MOVE_RATIO (!optimize_size))
-
 /* Undo the effects of the movmem pattern presence on STORE_BY_PIECES_P .  */
 #define MOVE_RATIO(SPEED) ((SPEED) ? 15 : 3)
 

[Patch 6/7 AArch64] Deprecate *_BY_PIECES_P, move to hookized version

2014-10-31 Thread James Greenhalgh

Hi,

This patch moves aarch64 to TARGET_USE_BY_PIECES_INFRASTRUCTURE_P.

AArch64 turns off STORE_BY_PIECES, so honour that and use the default
implementation for other operations.

Unlike the other patches in this series I do actually have some
hardware for AArch64! So this one has been through a bootstrap run
with no issues.

OK?

Cheers,
James

---
gcc/

2014-10-31  James Greenhalgh  james.greenha...@arm.com

* config/aarch64/aarch64.c
(aarch64_use_by_pieces_infrastructre_p): New.
(TARGET_USE_BY_PIECES_INFRASTRUCTURE): Likewise.
* config/aarch64/aarch64.h (STORE_BY_PIECES_P): Delete.
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 0400fd5..9aeac7c 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -10001,6 +10001,22 @@ aarch64_asan_shadow_offset (void)
   return (HOST_WIDE_INT_1  36);
 }
 
+static bool
+aarch64_use_by_pieces_infrastructure_p (unsigned int size,
+	unsigned int align,
+	enum by_pieces_operation op,
+	bool speed_p)
+{
+  /* STORE_BY_PIECES can be used when copying a constant string, but
+ in that case each 64-bit chunk takes 5 insns instead of 2 (LDR/STR).
+ For now we always fail this and let the move_by_pieces code copy
+ the string from read-only memory.  */
+  if (op == STORE_BY_PIECES)
+return false;
+
+  return default_use_by_pieces_infrastructure_p (size, align, op, speed_p);
+}
+
 #undef TARGET_ADDRESS_COST
 #define TARGET_ADDRESS_COST aarch64_address_cost
 
@@ -10253,6 +10269,10 @@ aarch64_asan_shadow_offset (void)
 #undef TARGET_LEGITIMIZE_ADDRESS
 #define TARGET_LEGITIMIZE_ADDRESS aarch64_legitimize_address
 
+#undef TARGET_USE_BY_PIECES_INFRASTRUCTURE_P
+#define TARGET_USE_BY_PIECES_INFRASTRUCTURE_P \
+  aarch64_use_by_pieces_infrastructure_p
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include gt-aarch64.h
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 97b1848..e22163e 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -723,12 +723,6 @@ do {	 \
 #define SET_RATIO(speed) \
   ((speed) ? 15 : AARCH64_CALL_RATIO - 2)
 
-/* STORE_BY_PIECES_P can be used when copying a constant string, but
-   in that case each 64-bit chunk takes 5 insns instead of 2 (LDR/STR).
-   For now we always fail this and let the move_by_pieces code copy
-   the string from read-only memory.  */
-#define STORE_BY_PIECES_P(SIZE, ALIGN) 0
-
 /* Disable auto-increment in move_by_pieces et al.  Use of auto-increment is
rarely a good idea in straight-line code since it adds an extra address
dependency between each instruction.  Better to use incrementing offsets.  */

[Patch 5/7 mips] Deprecate *_BY_PIECES_P, move to hookized version

2014-10-31 Thread James Greenhalgh

Hi,

This patch moves mips to TARGET_USE_BY_PIECES_INFRASTRUCTURE_P.

For MIPS, this means adapting mips_move_by_pieces_p (and fixing the
long-standing comment if this becomes a target hook, we should call
the default definition instead) and mips_store_by_pieces_p.

I tried building a compiler and there were no fires, I don't have access
to any MIPS hardware, so if one of the MIPS maintainers wanted to pick
this up and test it, that would be very much appreciated.

OK?

Thanks,
James

---
gcc/

2014-10-31  James Greenhalgh  james.greenha...@arm.com

* config/mips/mips.h (MOVE_BY_PIECES_P): Remove.
(STORE_BY_PIECES_P): Likewise.
* config/mips/mips.c (TARGET_USE_BY_PIECES_INFRASTRUCTURE_P): New.
(mips_move_by_pieces_p): Rename to...
(mips_use_by_pieces_infrastructure_p): ...this, use new hook
parameters, use the default hook implementation as a
fall-back.
diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c
index 3d9db92..ac7746c 100644
--- a/gcc/config/mips/mips.c
+++ b/gcc/config/mips/mips.c
@@ -7172,12 +7172,17 @@ mips_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
   return true;
 }
 
-/* Implement MOVE_BY_PIECES_P.  */
+/* Implement TARGET_USE_MOVE_BY_PIECES_INFRASTRUCTURE_P.  */
 
 bool
-mips_move_by_pieces_p (unsigned HOST_WIDE_INT size, unsigned int align)
+mips_use_by_pieces_infrastructure_p (unsigned int size,
+ unsigned int align,
+ enum by_pieces_operation op,
+ bool speed_p)
 {
-  if (HAVE_movmemsi)
+  if (op == STORE_BY_PIECES)
+return mips_store_by_pieces_p (size, align);
+  if (op == MOVE_BY_PIECES  HAVE_movmemsi)
 {
   /* movmemsi is meant to generate code that is at least as good as
 	 move_by_pieces.  However, movmemsi effectively uses a by-pieces
@@ -7194,13 +7199,12 @@ mips_move_by_pieces_p (unsigned HOST_WIDE_INT size, unsigned int align)
 	return size  UNITS_PER_WORD;
   return size = MIPS_MAX_MOVE_BYTES_STRAIGHT;
 }
-  /* The default value.  If this becomes a target hook, we should
- call the default definition instead.  */
-  return (move_by_pieces_ninsns (size, align, MOVE_MAX_PIECES + 1)
-	   (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()));
+
+  return default_use_by_pieces_infrastructure_p (size, align, op, speed_p);
 }
 
-/* Implement STORE_BY_PIECES_P.  */
+/* Implement a handler for STORE_BY_PIECES operations
+   for TARGET_USE_MOVE_BY_PIECES_INFRASTRUCTURE_P.  */
 
 bool
 mips_store_by_pieces_p (unsigned HOST_WIDE_INT size, unsigned int align)
@@ -19119,6 +19123,10 @@ mips_lra_p (void)
 #undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS
 #define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true
 
+#undef TARGET_USE_BY_PIECES_INFRASTRUCTURE_P
+#define TARGET_USE_BY_PIECES_INFRASTRUCTURE_P \
+  mips_use_by_pieces_infrastructure_p
+
 #undef TARGET_SPILL_CLASS
 #define TARGET_SPILL_CLASS mips_spill_class
 #undef TARGET_LRA_P
diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h
index c7b998b..bf19920 100644
--- a/gcc/config/mips/mips.h
+++ b/gcc/config/mips/mips.h
@@ -2872,9 +2872,6 @@ while (0)
? MIPS_MAX_MOVE_BYTES_STRAIGHT / MOVE_MAX		\
: MIPS_CALL_RATIO / 2)
 
-#define MOVE_BY_PIECES_P(SIZE, ALIGN) \
-  mips_move_by_pieces_p (SIZE, ALIGN)
-
 /* For CLEAR_RATIO, when optimizing for size, give a better estimate
of the length of a memset call, but use the default otherwise.  */
 
@@ -2887,9 +2884,6 @@ while (0)
 
 #define SET_RATIO(speed) \
   ((speed) ? 15 : MIPS_CALL_RATIO - 2)
-
-#define STORE_BY_PIECES_P(SIZE, ALIGN) \
-  mips_store_by_pieces_p (SIZE, ALIGN)
 
 /* Since the bits of the _init and _fini function is spread across
many object files, each potentially with its own GP, we must assume

[Patch 7/7] Remove *_BY_PIECES_P

2014-10-31 Thread James Greenhalgh

Hi,

This final patch gets rid of all the *_BY_PIECES_P macros.

Bootstrapped on x86_64, ARM and AArch64.

Thanks,
James

---
gcc/

2014-10-31  James Greenhalgh  james.greenha...@arm.com

* doc/tm.texi.in (MOVE_BY_PIECES_P): Remove.
(CLEAR_BY_PIECES_P): Likewise.
(SET_BY_PIECES_P): Likewise.
(STORE_BY_PIECES_P): Likewise.
* doc/tm.texi: Regenerate.
* system.h: Poison MOVE_BY_PIECES_P, CLEAR_BY_PIECES_P,
SET_BY_PIECES_P, STORE_BY_PIECES_P.
* expr.c (MOVE_BY_PIECES_P): Remove.
(CLEAR_BY_PIECES_P): Likewise.
(SET_BY_PIECES_P): Likewise.
(STORE_BY_PIECES_P): Likewise.
(can_move_by_pieces): Rewrite in terms of
targetm.use_by_pieces_infrastructure_p.
(emit_block_move_hints): Likewise.
(can_store_by_pieces): Likewise.
(store_by_pieces): Likewise.
(clear_storage_hints): Likewise.
(emit_push_insn): Likewise.
(expand_constructor): Likewise.
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index cfb8388..0d1f149 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -6123,16 +6123,6 @@ optimized for speed rather than size.
 If you don't define this, a reasonable default is used.
 @end defmac
 
-@defmac MOVE_BY_PIECES_P (@var{size}, @var{alignment})
-A C expression used to determine whether @code{move_by_pieces} will be used to
-copy a chunk of memory, or whether some other block move mechanism
-will be used.  Defaults to 1 if @code{move_by_pieces_ninsns} returns less
-than @code{MOVE_RATIO}.
-
-This macro is deprecated.  New ports should implement
-@code{TARGET_USE_BY_PIECES_INFRASTRUCTURE_P} instead.
-@end defmac
-
 @deftypefn {Target Hook} bool TARGET_USE_BY_PIECES_INFRASTRUCTURE_P (unsigned int @var{size}, unsigned int @var{alignment}, enum by_pieces_operation @var{op}, bool @var{speed_p})
 GCC will attempt several strategies when asked to copy between
 two areas of memory, or to set, clear or store to memory, for example
@@ -6184,16 +6174,6 @@ optimized for speed rather than size.
 If you don't define this, a reasonable default is used.
 @end defmac
 
-@defmac CLEAR_BY_PIECES_P (@var{size}, @var{alignment})
-A C expression used to determine whether @code{clear_by_pieces} will be used
-to clear a chunk of memory, or whether some other block clear mechanism
-will be used.  Defaults to 1 if @code{move_by_pieces_ninsns} returns less
-than @code{CLEAR_RATIO}.
-
-This macro is deprecated.  New ports should implement
-@code{TARGET_USE_BY_PIECES_INFRASTRUCTURE_P} instead.
-@end defmac
-
 @defmac SET_RATIO (@var{speed})
 The threshold of number of scalar move insns, @emph{below} which a sequence
 of insns should be generated to set memory to a constant value, instead of
@@ -6207,30 +6187,6 @@ optimized for speed rather than size.
 If you don't define this, it defaults to the value of @code{MOVE_RATIO}.
 @end defmac
 
-@defmac SET_BY_PIECES_P (@var{size}, @var{alignment})
-A C expression used to determine whether @code{store_by_pieces} will be
-used to set a chunk of memory to a constant value, or whether some
-other mechanism will be used.  Used by @code{__builtin_memset} when
-storing values other than constant zero.
-Defaults to 1 if @code{move_by_pieces_ninsns} returns less
-than @code{SET_RATIO}.
-
-This macro is deprecated.  New ports should implement
-@code{TARGET_USE_BY_PIECES_INFRASTRUCTURE_P} instead.
-@end defmac
-
-@defmac STORE_BY_PIECES_P (@var{size}, @var{alignment})
-A C expression used to determine whether @code{store_by_pieces} will be
-used to set a chunk of memory to a constant string value, or whether some
-other mechanism will be used.  Used by @code{__builtin_strcpy} when
-called with a constant source string.
-Defaults to 1 if @code{move_by_pieces_ninsns} returns less
-than @code{MOVE_RATIO}.
-
-This macro is deprecated.  New ports should implement
-@code{TARGET_USE_BY_PIECES_INFRASTRUCTURE_P} instead.
-@end defmac
-
 @defmac USE_LOAD_POST_INCREMENT (@var{mode})
 A C expression used to determine whether a load postincrement is a good
 thing to use for a given mode.  Defaults to the value of
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 3f66543..679b3d1 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -4600,16 +4600,6 @@ optimized for speed rather than size.
 If you don't define this, a reasonable default is used.
 @end defmac
 
-@defmac MOVE_BY_PIECES_P (@var{size}, @var{alignment})
-A C expression used to determine whether @code{move_by_pieces} will be used to
-copy a chunk of memory, or whether some other block move mechanism
-will be used.  Defaults to 1 if @code{move_by_pieces_ninsns} returns less
-than @code{MOVE_RATIO}.
-
-This macro is deprecated.  New ports should implement
-@code{TARGET_USE_BY_PIECES_INFRASTRUCTURE_P} instead.
-@end defmac
-
 @hook TARGET_USE_BY_PIECES_INFRASTRUCTURE_P
 
 @defmac MOVE_MAX_PIECES
@@ -4629,16 +4619,6 @@ optimized for speed rather than size.
 If you don't define this, a reasonable default 

RE: [Patch, MIPS] Add Octeon3 support

2014-10-31 Thread Moore, Catherine


 -Original Message-
 From: Hurugalawadi, Naveen
 [mailto:naveen.hurugalaw...@caviumnetworks.com]
 Sent: Friday, October 31, 2014 2:50 AM
 To: Moore, Catherine; Matthew Fortune; Myers, Joseph
 Cc: gcc-patches@gcc.gnu.org; Pinski, Andrew
 Subject: Re: [Patch, MIPS] Add Octeon3 support
 
 Hi Catherine,
 
  Would you please add some testcases and resubmit your patch?
 
 Thanks for the review and suggestions.
 Added the testcase gcc.target/mips/octeon3-pipe-1.c
 
 Please review the modified patch and let us know if its good.

This looks OK to commit.
Catherine

 
 2014-10-31  Andrew Pinski  apin...@cavium.com
 
 * config/mips/mips-cpus.def (octeon3): New cpu.
 * config/mips/mips.c (mips_rtx_cost_data): Add octeon3.
 (mips_print_operand case 'T', case 't'): Fix a bug as the mode
 of the comparison no longer matches mode of the operands.
 (mips_issue_rate): Handle PROCESSOR_OCTEON3.
 * config/mips/mips.h (TARGET_OCTEON):  Add Octeon3.
 (TARGET_OCTEON2): Likewise.
 (TUNE_OCTEON): Add Octeon3.
 * config/mips/mips.md (processor): Add octeon3.
 * config/mips/octeon.md (octeon_fpu): New automaton and cpu_unit.
 (octeon_arith): Add octeon3.
 (octeon_condmove): Remove.
 (octeon_condmove_o1): New reservation.
 (octeon_condmove_o2): New reservation.
 (octeon_condmove_o3_int_on_cc): New reservation.
 (octeon_load_o2): Add octeon3.
 (octeon_cop_o2): Likewise.
 (octeon_store): Likewise.
 (octeon_brj_o2): Likewise.
 (octeon_imul3_o2): Likewise.
 (octeon_imul_o2): Likewise.
 (octeon_mfhilo_o2): Likewise.
 (octeon_imadd_o2): Likewise.
 (octeon_idiv_o2_si): Likewise.
 (octeon_idiv_o2_di): Likewise.
 (octeon_fpu): Add to the automaton.
 (octeon_fpu): New cpu unit.
 (octeon_condmove_o2): Check for non floating point modes.
 (octeon_load_o2): Add prefetchx.
 (octeon_cop_o2): Don't check for octeon3.
 (octeon3_faddsubcvt): New reservation.
 (octeon3_fmul): Likewise.
 (octeon3_fmadd): Likewise.
 (octeon3_div_sf): Likewise.
 (octeon3_div_df): Likewise.
 (octeon3_sqrt_sf): Likewise.
 (octeon3_sqrt_df): Likewise.
 (octeon3_rsqrt_sf): Likewise.
 (octeon3_rsqrt_df): Likewise.
 (octeon3_fabsnegmov): Likewise.
 (octeon_fcond): Likewise.
 (octeon_fcondmov): Likewise.
 (octeon_fpmtc1): Likewise.
 (octeon_fpmfc1): Likewise.
 (octeon_fpload): Likewise.
 (octeon_fpstore): Likewise.
 * config/mips/mips-tables.opt: Regenerate.
 * doc/invoke.texi (-march=@var{arch}): Add octeon3.
 
 2014-10-31  Naveen H.S  naveen.hurugalaw...@caviumnetworks.com
 
 * gcc.target/mips/octeon3-pipe-1.c: New test.


[PATCH, i686] Fix for asan test failures with -m32 happened after EBX enabling in PIC mode

2014-10-31 Thread Zamyatin, Igor
Hi!

Following patch (moving initialization of pic_offset_table_rtx earlier) fixes 
failures for asan tests on 32 bits in PIC mode mentioned here - 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63534#c48


Bootstrapped/regtested on x86_64, i686

Is it ok for trunk?

ChangeLog:

2014-10-30  Igor Zamyatin  igor.zamya...@intel.com

* function.c (assign_parms): Move init of pic_offset_table_rtx
from here to...
* cfgexpand.c (expand_used_vars): ...here.

diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 9bd6135..cf7d94a 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -1718,6 +1718,11 @@ expand_used_vars (void)
 
   init_vars_expansion ();
 
+  /* Initialize pic_offset_table_rtx with a pseudo register
+ if required.  */
+  if (targetm.use_pseudo_pic_reg ())
+pic_offset_table_rtx = gen_reg_rtx (Pmode);
+
   hash_maptree, tree ssa_name_decls;
   for (i = 0; i  SA.map-num_partitions; i++)
 {
diff --git a/gcc/function.c b/gcc/function.c
index 1ef43c4..0bbcbbb 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -3464,11 +3464,6 @@ assign_parms (tree fndecl)
 
   fnargs.release ();
 
-  /* Initialize pic_offset_table_rtx with a pseudo register
- if required.  */
-  if (targetm.use_pseudo_pic_reg ())
-pic_offset_table_rtx = gen_reg_rtx (Pmode);
-
   /* Output all parameter conversion instructions (possibly including calls)
  now that all parameters have been copied out of hard registers.  */
   emit_insn (all.first_conversion_insn);


Re: [PATCH, Pointer Bounds Checker 14/x] Passes [1/n] Expand interfaces

2014-10-31 Thread Jeff Law

On 10/30/14 10:37, Ilya Enkovich wrote:


Hi,

I rebased patches on current trunk.  Bootstrap and check are clean on
linux-x86_64.

Darwin bootstrap has few issues due to IPA ICF pass.  I also found my
patches introduce an unused variable warning due to conditional code
(under #ifdef ASM_OUTPUT_DEF) in varasm.  With IPA ICF disabled and
this warning fixed Darwin 64 bootstrap is OK.

Excellent.



ARM cross build revealed another problem with conditional code.
Function immed_double_const was put under #if
(TARGET_SUPPORTS_WIDE_INT == 0) some time ago but I missed it and
didn't update my patches.  With this fixed cross build is also OK.
Thanks for taking the extra time to test ARM too.  It is greatly 
appreciated.


FWIW,  I'd like to see the amount of #if conditional code go down over 
time.  The glibc team is making a similar change and while painful I do 
thing it brings noticeable long term maintenance benefits.  But that's 
clearly out of scope for this stuff ;-)





Below are required changes.  If these fixes are OK, I'm ready to
commit whole series (I'm going to commit it as a single patch because
didn't test each part separately).

They're fine.   ANd yes, please commit as a single patch.

Thanks for your patience on this stuff, I know it's been a long slow 
process.

jeff


Re: [gofrontend-dev] Re: [PATCH 7/9] Gccgo port to s390[x] -- part I

2014-10-31 Thread Ian Taylor
On Fri, Oct 31, 2014 at 2:11 AM, Dominik Vogt v...@linux.vnet.ibm.com wrote:
 On Thu, Oct 30, 2014 at 07:51:45AM -0700, Ian Taylor wrote:
 On Thu, Oct 30, 2014 at 12:25 AM, Dominik Vogt v...@linux.vnet.ibm.com 
 wrote:
  See attached patch.

 I don't mind skipping the test on other platforms, but xfail is not
 correct.  When an xfail test passes, we get an XPASS error from the
 testsuite.  We need dg-skip-if.  I committed this patch.

 That is exactly the reason why I chose dg-xfail-if:  To identify
 the targets where the test works out of the box, because I think
 there won't be many of them.

That would be fine if coupled with an immediate plan to test on all
systems.  What we don't want is an XPASS on some random system six
months from now that forces some poor GCC developer who knows nothing
at all about this code to figure out what is going on.


 But anyway, we can leave it as it is for the moment and eventually
 I'll get around cleaning that up.

OK.

Ian


Re: [PATCH] x86: extend vect-args testcase to AVX flavors

2014-10-31 Thread Kirill Yukhin
On 30 Oct 09:32, Uros Bizjak wrote:
 On Thu, Oct 30, 2014 at 8:50 AM, Jan Beulich jbeul...@suse.com wrote:
  gcc/testsuite:
  2014-10-30  Jan Beulich  jbeul...@suse.com
 
  * gcc.target/i386/i386.exp: Extend option set to test
  vect-args.c with to include -mavx, -mavx2, and -mavx512f.
  * gcc.target/i386/vect-args.c: Add AVX* modes and tests.
 
 OK, but let's also wait for Kirill's opinion.
I like the change.

--
Thanks, K
 
 Thanks,
 Uros.
 
  --- a/gcc/testsuite/gcc.target/i386/i386.exp
  +++ b/gcc/testsuite/gcc.target/i386/i386.exp
  @@ -318,9 +318,9 @@ clearcap-init
 
   global runtests
   # Special case compilation of vect-args.c so we don't have to
  -# replicate it 10 times.
  +# replicate it 16 times.
   if [runtest_file_p $runtests $srcdir/$subdir/vect-args.c] {
  -  foreach type {  -mmmx -m3dnow -msse -msse2 } {
  +  foreach type {  -mmmx -m3dnow -msse -msse2 -mavx -mavx2 -mavx512f } {
   foreach level {  -O } {
 set flags $type $level
 verbose -log Testing vect-args, $flags 1
  --- a/gcc/testsuite/gcc.target/i386/vect-args.c
  +++ b/gcc/testsuite/gcc.target/i386/vect-args.c
  @@ -1,6 +1,22 @@
   /* { dg-do compile } */
   /* { dg-options -w -Wno-psabi } */
 
  +/* AVX512F and AVX512BW modes.  */
  +typedef unsigned char V64QImode __attribute__((vector_size(64)));
  +typedef unsigned short V32HImode __attribute__((vector_size(64)));
  +typedef unsigned int V16SImode __attribute__((vector_size(64)));
  +typedef unsigned long long V8DImode __attribute__((vector_size(64)));
  +typedef float V16SFmode __attribute__((vector_size(64)));
  +typedef double V8DFmode __attribute__((vector_size(64)));
  +
  +/* AVX and AVX2 modes.  */
  +typedef unsigned char V32QImode __attribute__((vector_size(32)));
  +typedef unsigned short V16HImode __attribute__((vector_size(32)));
  +typedef unsigned int V8SImode __attribute__((vector_size(32)));
  +typedef unsigned long long V4DImode __attribute__((vector_size(32)));
  +typedef float V8SFmode __attribute__((vector_size(32)));
  +typedef double V4DFmode __attribute__((vector_size(32)));
  +
   /* SSE1 and SSE2 modes.  */
   typedef unsigned char V16QImode __attribute__((vector_size(16)));
   typedef unsigned short V8HImode __attribute__((vector_size(16)));
  @@ -21,12 +37,27 @@ extern TYPE data_##TYPE;\
   void r_##TYPE (TYPE x) { data_##TYPE = x; }\
   void s_##TYPE (void) { r_##TYPE (data_##TYPE); }
 
  +TEST(V64QImode)
  +TEST(V32HImode)
  +TEST(V16SImode)
  +TEST(V8DImode)
  +TEST(V16SFmode)
  +TEST(V8DFmode)
  +
  +TEST(V32QImode)
  +TEST(V16HImode)
  +TEST(V8SImode)
  +TEST(V4DImode)
  +TEST(V8SFmode)
  +TEST(V4DFmode)
  +
   TEST(V16QImode)
   TEST(V8HImode)
   TEST(V4SImode)
   TEST(V2DImode)
   TEST(V4SFmode)
   TEST(V2DFmode)
  +
   TEST(V8QImode)
   TEST(V4HImode)
   TEST(V2SImode)
 
 
 


Re: [gomp4] OpenACC wait directive

2014-10-31 Thread Cesar Philippidis
On 10/06/2014 03:56 AM, Ilmir Usmanov wrote:

 Otherwise, Fortran part looks good for me.

Thanks for the review again! I applied this patch to gomp-4_0-branch now
that the middle end pieces are in place.

Thanks,
Cesar
2014-10-31  Cesar Philippidis  ce...@codesourcery.com

	gcc/fortran/
	* gfortran.h (struct gfc_omp_clauses): Remove non_clause_wait_expr.
	* dump-parse-tree.c (show_omp_clauses): Likewise.
	* openmp.c (gfc_free_omp_clauses): Likewise.
	(gfc_match_omp_clauses): Update handling of async.
	(OACC_WAIT_CLAUSE_MASK): New define.
	(gfc_match_oacc_wait): Make the wait directive comply with OpenACC 2.0.
	(resolve_omp_clauses): Use resolve_oacc_scalar_in_expr inspect
	arguments to the wait clause.
	(resolve_oacc_wait): Remove.
	(gfc_resolve_oacc_directive): Handle EXEC_OACC_WAIT with
	resolve_omp_clauses.
	* trans-openmp.c (gfc_trans_omp_clauses): Update handling of OpenACC
	wait arguments.
	(gfc_trans_oacc_executable_directive): Remove EXEC_OACC_WAIT.
	(gfc_trans_oacc_wait_directive): New function.
	(gfc_trans_oacc_directive): Use it.

	gcc/testsuite/
	* gfortran.dg/goacc/asyncwait-1.f95: New test.
	* gfortran.dg/goacc/asyncwait-2.f95: New test.
	* gfortran.dg/goacc/asyncwait-3.f95: New test.
	* gfortran.dg/goacc/asyncwait-4.f95: New test.

	libgomp
	* testsuite/libgomp.oacc-fortran/asyncwait-1.f90: New test.
	* testsuite/libgomp.oacc-fortran/asyncwait-2.f90: New test.
	* testsuite/libgomp.oacc-fortran/asyncwait-3.f90: New test.


diff --git a/gcc/fortran/dump-parse-tree.c b/gcc/fortran/dump-parse-tree.c
index d7f2182..f85f6b6 100644
--- a/gcc/fortran/dump-parse-tree.c
+++ b/gcc/fortran/dump-parse-tree.c
@@ -1173,12 +1173,6 @@ show_omp_clauses (gfc_omp_clauses *omp_clauses)
 	  fputc (')', dumpfile);
 	}
 }
-  if (omp_clauses-non_clause_wait_expr)
-{
-  fputc ('(', dumpfile);
-  show_expr (omp_clauses-non_clause_wait_expr);
-  fputc (')', dumpfile);
-}
   if (omp_clauses-sched_kind != OMP_SCHED_NONE)
 {
   const char *type;
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 4b1724b..adfa1b2 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1264,7 +1264,6 @@ typedef struct gfc_omp_clauses
   struct gfc_expr *num_gangs_expr;
   struct gfc_expr *num_workers_expr;
   struct gfc_expr *vector_length_expr;
-  struct gfc_expr *non_clause_wait_expr;
   gfc_expr_list *wait_list;
   gfc_expr_list *tile_list;
   unsigned async:1, gang:1, worker:1, vector:1, seq:1, independent:1;
diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index 4a48335..c158128 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -83,7 +83,6 @@ gfc_free_omp_clauses (gfc_omp_clauses *c)
   gfc_free_expr (c-num_gangs_expr);
   gfc_free_expr (c-num_workers_expr);
   gfc_free_expr (c-vector_length_expr);
-  gfc_free_expr (c-non_clause_wait_expr);
   for (i = 0; i  OMP_LIST_NUM; i++)
 gfc_free_omp_namelist (c-lists[i]);
   gfc_free_expr_list (c-wait_list);
@@ -496,10 +495,15 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, unsigned long long mask,
 	if (gfc_match (async) == MATCH_YES)
 	  {
 	c-async = true;
-	if (gfc_match ( ( %e ), c-async_expr) == MATCH_YES)
-	  needs_space = false;
-	else
-	  needs_space = true;
+	needs_space = false;
+	if (gfc_match ( ( %e ), c-async_expr) != MATCH_YES)
+	  {
+		c-async_expr = gfc_get_constant_expr (BT_INTEGER,
+		   gfc_default_integer_kind,
+		  gfc_current_locus);
+		/* TODO XXX: FIX -1 (acc_async_noval).  */
+		mpz_set_si (c-async_expr-value.integer, -1);
+	  }
 	continue;
 	  }
   if ((mask  OMP_CLAUSE_GANG)  !c-gang)
@@ -1168,6 +1172,8 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, unsigned long long mask,
 #define OACC_EXIT_DATA_CLAUSES \
   (OMP_CLAUSE_IF | OMP_CLAUSE_ASYNC | OMP_CLAUSE_WAIT | OMP_CLAUSE_COPYOUT \
| OMP_CLAUSE_DELETE)
+#define OACC_WAIT_CLAUSES \
+  (OMP_CLAUSE_ASYNC)
 
 
 match
@@ -1328,8 +1334,38 @@ match
 gfc_match_oacc_wait (void)
 {
   gfc_omp_clauses *c = gfc_get_omp_clauses ();
-  gfc_match ( ( %e ), c-non_clause_wait_expr);
+  gfc_expr_list *wait_list = NULL, *el;
+
+  match_oacc_expr_list ( (, wait_list, true);
+  gfc_match_omp_clauses (c, OACC_WAIT_CLAUSES, false, false, true);
+
+  if (gfc_match_omp_eos () != MATCH_YES)
+{
+  gfc_error (Unexpected junk in !$ACC WAIT at %C);
+  return MATCH_ERROR;
+}
+
+  if (wait_list)
+for (el = wait_list; el; el = el-next)
+  {
+	if (el-expr == NULL)
+	  {
+	gfc_error (Invalid argument to $!ACC WAIT at %L,
+		   wait_list-expr-where);
+	return MATCH_ERROR;
+	  }
+
+	if (!gfc_resolve_expr (el-expr)
+	|| el-expr-ts.type != BT_INTEGER || el-expr-rank != 0
+	|| el-expr-expr_type != EXPR_CONSTANT)
+	  {
+	gfc_error (WAIT clause at %L requires a scalar INTEGER expression,
+		   el-expr-where);
 
+	return MATCH_ERROR;
+	  }
+  }
+  c-wait_list = wait_list;
   new_st.op = EXEC_OACC_WAIT;
   new_st.ext.omp_clauses = c;
   return 

Re: [PATCH x86] Increase PARAM_MAX_COMPLETELY_PEELED_INSNS when branch is costly

2014-10-31 Thread Evgeny Stupachenko
I've measured spec2000, spec2006 as well and EEMBC for Silvermont in addition.
100-120 change gives gain for Silvermont, the results on Haswell are flat.

On Fri, Oct 31, 2014 at 3:14 PM, Eric Botcazou ebotca...@adacore.com wrote:
 Agreed, I think the value of 100 was set decade ago by Zdenek and me
 completely artifically. I do not recall any serious tuning of this flag.

 Are you talking bout PARAM_MAX_COMPLETELY_PEELED_INSNS here?  If so, see:
   https://gcc.gnu.org/ml/gcc-patches/2012-11/msg01193.html

 We have experienced performance regressions because of this arbitrary change
 and bumped it back to 200 unconditionally.

 --
 Eric Botcazou


Re: [PATCH] microblaze: microblaze.md: Use 'SI' instead of 'VOID' for operand 1 of 'call_value_intern'

2014-10-31 Thread Chen Gang

At present, I use telnet (without password), login to microblaze qemu
successfully!  :-)

 - I compile busy box with the glibc in orginal 'ramfs', so get telnetd:
   use new busybox replace the old one, and add symbol link 'telnetd' to
   busybox in /bin.

 - configure qemu with network support (device xlnx.xps-ethernetlite).

   yum install libvirt
   yum install tunctl
   tunctl -b
   ip link set tap0 up
   brctl addif virbr0 tap0
   ./microblaze-softmmu/qemu-system-microblaze -M petalogix-s3adsp1800 \
 -kernel ../linux-stable.microblaze/arch/microblaze/boot/linux.bin \
 -no-reboot -append console=ttyUL0,115200 doreboot -nographic \
 -net nic,vlan=0,model=xlnx.xps-ethernetlite,macaddr=00:16:35:AF:94:00 \
 -net tap,vlan=0,ifname=tap0,script=no,downscript=no

 - fix a kernel bug: add xlnx,xps-ethernetlite-2.00.b for compatible
   with its firmware (can find it under /sys/firmware/compatible,
   within microblaze qemu bash environments). Related diff:

   diff --git a/drivers/net/ethernet/xilinx/xilinx_emaclite.c 
b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
   index 28dbbdc..298fad3 100644
   --- a/drivers/net/ethernet/xilinx/xilinx_emaclite.c
   +++ b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
   @@ -1236,6 +1236,7 @@ static struct of_device_id xemaclite_of_match[] = {
   { .compatible = xlnx,opb-ethernetlite-1.01.b, },
   { .compatible = xlnx,xps-ethernetlite-1.00.a, },
   { .compatible = xlnx,xps-ethernetlite-2.00.a, },
   +   { .compatible = xlnx,xps-ethernetlite-2.00.b, },
   { .compatible = xlnx,xps-ethernetlite-2.01.a, },
   { .compatible = xlnx,xps-ethernetlite-3.00.a, },
   { /* end of list */ },

Next, I shall send related kernel patch for upstream kernel, and continue
for microbaze DejaGNU with microbaze qemu, and sorry again, I did not
finish it within this month.


Thanks.


On 10/30/14 22:04, Chen Gang wrote:
 On 10/29/14 23:58, Chen Gang wrote:
 On 10/27/14 9:42, Chen Gang wrote:
 On 10/27/14 2:22, Michael Eager wrote:

 Microblaze-sim provides basic instruction set architecture and memory 
 simulation.
 There is no operating system support.  (It's also quite old.  I'm not sure
 which version of the MB architecture it models, but it is not recent.)

 Microblaze-sim is not a full system simulator, like QEMU.  To be able to
 run a program which requires glibc, you need to be able to boot a full 
 Linux
 image on the simulator, which microblaze-sim cannot do.  QEMU models an
 entire processor and can boot a Linux image.


 At present, run upstream qemu 2.1.2 and upstream Linux kernel 3.17-rc7
 with simple ramfs successfully. Via modify ramfs, can run hello world
 program with static glibc (built by upstream mc_gcc), successfully.

 
 After copy the ramfs' /lib and /usr/lib to outside, build the hello
 world program again with the dynamic glibc, then put it to ramfs. The
 hello world program with dynamic glibc can run correctly inside qemu :-)
 
 Next, I need focus on networking (I have found qemu related device, and
 kernel related device, and I also know, it needs telnetd in busy box).
 But sorry, it seems I can not finish within this month :-(
 
  - I wasted much time resources on choosing qemu or sim, next I should
notice about it (do not waste time, again).
 
  - and another excuse is: I have to do it in my free time (within 2.5
hours per day, in average). My current job is not related with it
(at present, it is about Global Platform Java applet for iPhone OS).
 
 Next month:
 
  - I should finish microblaze qemu test under DejaGNU, should finish
within next month (2014-11-30).
 
  - I also shall start tile cross compiling for gcc/binutils, and use it
to Linux kernel, and test it with qemu. I shall try to finish them
within 2 months (finish before 2014-12-31).
 
  - At least, finish 1 patch for gcc, 1 patch for binutils, 1 patch for
qemu/kvm/xen, 3 patches for kernel, within next month (2014-11-30).
 
 
 Welcome any ideas, suggestions or completions.
 
 Thanks.
 
  - For ramfs:

wget 
 http://www.wiki.xilinx.com/file/view/microblaze_complete.cpio.gz/419243588/microblaze_complete.cpio.gz

  - Related qemu command:

./microblaze-softmmu/qemu-system-microblaze -M petalogix-s3adsp1800 \
  -kernel ../linux-stable.microblaze/arch/microblaze/boot/linux.bin \
  -no-reboot -append console=ttyUL0,115200 doreboot -nographic

 Next, I shall try to let our gdb and DejaGNU work for it:

  - How to let qemu support network and rsh (ramfs need telnetd, kernel
may need related driver, and qemu related hardware need be tested).

  - Let gdb work for it, then config DejaGNU (need we test the program
with dynamic glib, it will be fail now for not match glibc version
in ramfs).

  - At last, run our test.

 It seems, still many things need trying. Welcome any ideas, suggestions,
 and completions for it (especially for ramfs network and/or glibc, and
 DejaGNU configuration ...).

[PATCH 00/27] Merger of jit branch v3

2014-10-31 Thread David Malcolm
I'd like to merge the JIT branch into trunk:
  https://gcc.gnu.org/wiki/JIT

This is v3 since it incorporates fixes for various issues
identified in earlier submissions:
  v1: https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02056.html
  v2: https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01168.html

I've merged some of the work approved earlier into trunk.

Of the remaining work, some has already been approved, and some
hasn't.  I've split the latter up into more fine-grained patches
in the hope it will make review easier, so there are 27 patches
in this kit, compared to 10 in the earlier one.

Here's an overview of the patches:

  01/27: gcc: configure and Makefile changes needed by jit
Needs review.
Corresponds to:
  [PATCH 2/5] gcc: configure and Makefile changes needed by jit
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01169.html
and has had cleanups in response to concerns from Jeff and Joseph,
to remove the need to install when running the jit testsuite.

  02/27: JIT-related changes outside of jit subdir
Already approved by Jeff.

  03/27: Add Sphinx to install.texi
Needs review.

Patches 04-18 correspond to:
  [PATCH 06/10] Heart of the JIT implementation
  (was: Re: [PATCH 0/5] Merger of jit branch (v2))
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01247.html
from v2; I've broken them up by file to make them easier to review:

  04/27: New file: gcc/jit/notes.txt
  05/27: New file: gcc/jit/config-lang.in
  06/27: New file: gcc/jit/Make-lang.in
  07/27: New file: gcc/jit/dummy-frontend.c
  08/27: New file: gcc/jit/libgccjit.h
  09/27: New file: gcc/jit/libgccjit.map
  10/27: New file: gcc/jit/libgccjit.c
  11/27: New file: gcc/jit/jit-common.h
  12/27: New file: gcc/jit/jit-recording.h
  13/27: New file: gcc/jit/jit-recording.c
  14/27: New files: gcc/jit/jit-builtins.{c|h}
  15/27: New file: gcc/jit/jit-playback.h
  16/27: New file: gcc/jit/jit-playback.c
  17/27: New file: gcc/jit/libgccjit++.h
  18/27: New file: gcc/jit/TODO.rst
All of these need review.

  19/27: Testsuite for the JIT
Earlier version already approved by Jeff, only small changes since.

  20/27: Documentation: Makefile and conf.py
  21/27: Documentation: the examples subdirectory
  22/27: Documentation: top-level index.rst
  23/27: Documentation: the intro subdirectory
  24/27: Documentation: add topics subdirectory
  25/27: Documentation: add internals subdirectory
All of these need review.
Patches 20-25 correspond to:
  [PATCH 08/10] Documentation for the JIT library
  (Re: Patches 5-10 of jit merger)
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01392.html
from v2.  Since then, I've:
  * eliminated all mentions of pkg-config (since we no longer
support this)
  * eliminated the installation section and the discussion of
packages
  * converted the final page (docs/internals/index.rst) into a
short guide for contributors to the project (e.g. myself and
other maintainers)
 Prebuilt HTML from this can be seen at:
   https://dmalcolm.fedorapeople.org/gcc/libgccjit-api-docs/index.html
 Again, I've broken them up into smaller patches to make them
 easier to review.

  26/27: Prebuilt texinfo documentation for the JIT library
Already (pre)approved by Jeff.

  27/27: ChangeLog files
Earlier version approved by Jeff, and presumably all changes
since count as obvious.

I've successfully bootstrapped and regression-tested the cumulative
result of all of the patches against a control build, building them
both with --enable-host-shared, and with
  --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto
adding ,jit to the test build (both on x86_64-unknown-linux-gnu;
Fedora 20, using Monday's r216746 as the baseline).

There were no regressions vs the control build, and the patched build
gains a jit.sum, with 4663 passes (and no failures).

OK for trunk?
(patches 01, 03, 04-18, 20-25 are the ones needing review)

Overall diffstat follows:

 ChangeLog.jit  |   23 +
 MAINTAINERS|1 +
 contrib/ChangeLog.jit  |   14 +
 contrib/jit-coverage-report.py |   67 +
 gcc/ChangeLog.jit  |  360 ++
 gcc/Makefile.in|   20 +-
 gcc/configure  |   52 +-
 gcc/configure.ac   |   10 +
 gcc/doc/install.texi   |7 +-
 gcc/java/ChangeLog.jit |   14 +
 gcc/jit/ChangeLog  |9 +
 gcc/jit/ChangeLog.jit  | 3342 ++
 gcc/jit/Make-lang.in   |  298 +
 gcc/jit/TODO.rst   |  119 +
 gcc/jit/config-lang.in |   38 +
 gcc/jit/docs/Makefile

[PATCH 01/27] gcc: configure and Makefile changes needed by jit

2014-10-31 Thread David Malcolm
An earlier version of this was posted as:
  [PATCH 2/5] gcc: configure and Makefile changes needed by jit
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01169.html

Since then, I've eliminated the gcc_version, bindir, and pkgconfigdir
additions, and added the FULL_DRIVER_NAME variable and symlink, to
avoid the need to install when running the jit testsuite.

gcc/ChangeLog:
* Makefile.in (doc_build_sys): New variable, set to sphinx if
sphinx is installed, falling back to texinfo otherwise.
(FULL_DRIVER_NAME): New variable, adapted from the
install-driver target.  New target, a symlink within the builddir,
linked to xgcc, for use when running the JIT library from the
builddir.
(MOSTLYCLEANFILES): Add FULL_DRIVER_NAME.
(install-driver): Use $(FULL_DRIVER_NAME) rather than spelling it
out.

* configure.ac (doc_build_sys): New variable, set to sphinx if
sphinx is installed, falling back to texinfo otherwise.
(GCC_DRIVER_NAME): Generate a gcc-driver-name.h file containing
GCC_DRIVER_NAME for the benefit of jit/internal-api.c.

* configure: Regenerate.
---
 gcc/Makefile.in  | 20 +---
 gcc/configure| 52 ++--
 gcc/configure.ac | 10 ++
 3 files changed, 77 insertions(+), 5 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index e2100ff..ded7471 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -316,6 +316,11 @@ write_entries_to_file = $(shell rm -f $(2) || :) $(shell 
touch $(2)) \
  $(shell expr $(range) + 
$(write_entries_to_file_split) - 1), $(1)) \
 | tr ' ' '\012'  $(2)))
 
+# The jit documentation looks better if built with sphinx, but can be
+# built with texinfo if sphinx is not available.
+# configure sets doc_build_sys to sphinx or texinfo accordingly
+doc_build_sys=@doc_build_sys@
+
 # 
 # UNSORTED
 # 
@@ -1504,6 +1509,9 @@ BACKEND = libbackend.a main.o @TREEBROWSER@ 
libcommon-target.a libcommon.a \
 # front-end checking.
 TREECHECKING = @TREECHECKING@
 
+# The full name of the driver on installation
+FULL_DRIVER_NAME=$(target_noncanonical)-gcc-$(version)$(exeext)
+
 MOSTLYCLEANFILES = insn-flags.h insn-config.h insn-codes.h \
  insn-output.c insn-recog.c insn-emit.c insn-extract.c insn-peep.c \
  insn-attr.h insn-attr-common.h insn-attrtab.c insn-dfatab.c \
@@ -1511,7 +1519,7 @@ MOSTLYCLEANFILES = insn-flags.h insn-config.h 
insn-codes.h \
  tm-preds.h tm-constrs.h checksum-options gimple-match.c generic-match.c \
  tree-check.h min-insn-modes.c insn-modes.c insn-modes.h \
  genrtl.h gt-*.h gtype-*.h gtype-desc.c gtyp-input.list \
- xgcc$(exeext) cpp$(exeext) \
+ xgcc$(exeext) cpp$(exeext) $(FULL_DRIVER_NAME) \
  $(EXTRA_PROGRAMS) gcc-cross$(exeext) \
  $(SPECS) collect2$(exeext) gcc-ar$(exeext) gcc-nm$(exeext) \
  gcc-ranlib$(exeext) \
@@ -1520,6 +1528,12 @@ MOSTLYCLEANFILES = insn-flags.h insn-config.h 
insn-codes.h \
  gengtype$(exeext) *.[0-9][0-9].* *.[si] *-checksum.c libbackend.a \
  libcommon-target.a libcommon.a libgcc.mk
 
+# This symlink makes the full installation name of the driver be available
+# from within the *build* directory, for use when running the JIT library
+# from there (e.g. when running its testsuite).
+$(FULL_DRIVER_NAME): ./xgcc
+   $(LN) -s $ $@
+
 #
 # Language makefile fragments.
 
@@ -3280,9 +3294,9 @@ install-driver: installdirs xgcc$(exeext)
-rm -f $(DESTDIR)$(bindir)/$(GCC_INSTALL_NAME)$(exeext)
-$(INSTALL_PROGRAM) xgcc$(exeext) 
$(DESTDIR)$(bindir)/$(GCC_INSTALL_NAME)$(exeext)
-if [ $(GCC_INSTALL_NAME) != $(target_noncanonical)-gcc-$(version) 
]; then \
- rm -f 
$(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-$(version)$(exeext); \
+ rm -f $(DESTDIR)$(bindir)/$(FULL_DRIVER_NAME); \
  ( cd $(DESTDIR)$(bindir)  \
-   $(LN) $(GCC_INSTALL_NAME)$(exeext) 
$(target_noncanonical)-gcc-$(version)$(exeext) ); \
+   $(LN) $(GCC_INSTALL_NAME)$(exeext) $(FULL_DRIVER_NAME) ); \
fi
-if [ ! -f gcc-cross$(exeext) ] \
 [ $(GCC_INSTALL_NAME) != $(GCC_TARGET_INSTALL_NAME) ]; then \
diff --git a/gcc/configure b/gcc/configure
index 16f128f..6779b2a 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -743,6 +743,7 @@ CXXDEPMODE
 DEPDIR
 am__leading_dot
 CXXCPP
+doc_build_sys
 AR
 NM
 BISON
@@ -8069,6 +8070,47 @@ fi
 
 fi
 
+# The jit documentation looks better if built with sphinx, but can be
+# built with texinfo if sphinx is not available.
+# Set doc_build_sys to sphinx or texinfo accordingly.
+# Extract the first word of sphinx-build, so it can be a program name with 
args.
+set dummy sphinx-build; ac_word=$2
+{ $as_echo $as_me:${as_lineno-$LINENO}: checking for $ac_word 5
+$as_echo_n checking for $ac_word...  6; }
+if test ${ac_cv_prog_doc_build_sys+set} = set; then :
+  $as_echo_n (cached)  6
+else
+  if test -n $doc_build_sys; then
+  

[PATCH 03/27] Add Sphinx to install.texi

2014-10-31 Thread David Malcolm
In https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01793.html,
Joseph said:

 Although Sphinx isn't a build dependency, as a dependency for
 regenerating checked-in files I think it should be documented in
 install.texi (like autoconf, gettext, etc.).

This patch adds such documentation.

gcc/ChangeLog:
* doc/install.texi (Tools/packages necessary for modifying GCC):
Add Sphinx.
---
 gcc/doc/install.texi | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 06fcd8a..ef7656c 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -491,6 +491,11 @@ Necessary for running @command{texi2dvi} and 
@command{texi2pdf}, which
 are used when running @command{make dvi} or @command{make pdf} to create
 DVI or PDF files, respectively.
 
+@item Sphinx version 1.0 (or later)
+
+Necessary to regenerate @file{jit/docs/_build/texinfo} from the @file{.rst}
+files in the directories below @file{jit/docs}.
+
 @item SVN (any version)
 @itemx SSH (any version)
 
-- 
1.8.5.3



[PATCH 02/27] JIT-related changes outside of jit subdir

2014-10-31 Thread David Malcolm
This was previously posted as:
  [PATCH 05/10] JIT-related changes outside of jit subdir
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01246.html

and approved by Jeff in
  https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01410.html
 OK if/when rest of JIT bits are approved.

Joseph pointed out that I should add a note about sphinx
as a dependency to install.texi:
  https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01793.html
I do that in the next patch.

ChangeLog:
* MAINTAINERS (Various Maintainers): Add myself as jit maintainer.

contrib/ChangeLog:
* jit-coverage-report.py: New file: a script to print crude
code-coverage information for the libgccjit API.

gcc/ChangeLog:
* doc/install.texi (--enable-host-shared): Specify that this is
required when building libgccjit.
* timevar.def (TV_JIT_REPLAY): New.
(TV_ASSEMBLE): New.
(TV_LINK): New.
(TV_LOAD): New.
---
 MAINTAINERS|  1 +
 contrib/jit-coverage-report.py | 67 ++
 gcc/doc/install.texi   |  2 +-
 gcc/timevar.def|  6 
 4 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 contrib/jit-coverage-report.py

diff --git a/MAINTAINERS b/MAINTAINERS
index 11a28ef..3a7cf6f8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -260,6 +260,7 @@ testsuite   Janis Johnson   
jani...@codesourcery.com
 register allocationVladimir Makarovvmaka...@redhat.com
 gdbhooks.pyDavid Malcolm   dmalc...@redhat.com
 SLSR   Bill Schmidtwschm...@linux.vnet.ibm.com
+jitDavid Malcolm   dmalc...@redhat.com
 
 Note that individuals who maintain parts of the compiler need approval to
 check in changes outside of the parts of the compiler they maintain.
diff --git a/contrib/jit-coverage-report.py b/contrib/jit-coverage-report.py
new file mode 100644
index 000..529336f
--- /dev/null
+++ b/contrib/jit-coverage-report.py
@@ -0,0 +1,67 @@
+#! /usr/bin/python
+#
+# Print a report on which libgccjit.so symbols are used in which test
+# cases, and which lack test coverage.  Tested with Python 2.7 and 3.2
+# To be run from the root directory of the source tree.
+#
+# Copyright (C) 2014 Free Software Foundation, Inc.
+# Written by David Malcolm dmalc...@redhat.com.
+#
+# This script is Free Software, and it can be copied, distributed and
+# modified as defined in the GNU General Public License.  A copy of
+# its license can be downloaded from http://www.gnu.org/copyleft/gpl.html
+
+from collections import Counter
+import glob
+import re
+import sys
+
+def parse_map_file(path):
+
+Parse libgccjit.map, returning the symbols in the API as a list of str.
+
+syms = []
+with open(path) as f:
+for line in f:
+m = re.match('^\s+([a-z_]+);$', line)
+if m:
+syms.append(m.group(1))
+return syms
+
+def parse_test_case(path):
+
+Locate all symbol-like things in a C test case, yielding
+them as a sequence of str.
+
+with open(path) as f:
+for line in f:
+for m in re.finditer('([_A-Za-z][_A-Za-z0-9]*)', line):
+yield m.group(1)
+
+def find_test_cases():
+for path in glob.glob('gcc/testsuite/jit.dg/*.[ch]'):
+yield path
+
+api_syms = parse_map_file('gcc/jit/libgccjit.map')
+
+syms_in_test_cases = {}
+for path in find_test_cases():
+syms_in_test_cases[path] = list(parse_test_case(path))
+
+uses = Counter()
+for sym in sorted(api_syms):
+print('symbol: %s' % sym)
+uses[sym] = 0
+for path in syms_in_test_cases:
+count = syms_in_test_cases[path].count(sym)
+uses[sym] += count
+if count:
+print('  uses in %s: %i' % (path, count))
+if uses[sym] == 0:
+print('  NEVER USED')
+sys.stdout.write('\n')
+
+layout = '%40s  %5s  %s'
+print(layout % ('SYMBOL', 'USES', 'HISTOGRAM'))
+for sym, count in uses.most_common():
+print(layout % (sym, count, '*' * count if count else 'UNUSED'))
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 3df78ff..06fcd8a 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -954,7 +954,7 @@ Specify that the @emph{host} code should be built into 
position-independent
 machine code (with -fPIC), allowing it to be used within shared libraries,
 but yielding a slightly slower compiler.
 
-Currently this option is only of use to people developing GCC itself.
+This option is required when building the libgccjit.so library.
 
 Contrast with @option{--enable-shared}, which affects @emph{target}
 libraries.
diff --git a/gcc/timevar.def b/gcc/timevar.def
index 96b6069..6968a06 100644
--- a/gcc/timevar.def
+++ b/gcc/timevar.def
@@ -279,3 +279,9 @@ DEFTIMEVAR (TV_VERIFY_LOOP_CLOSED, verify loop closed)
 DEFTIMEVAR (TV_VERIFY_RTL_SHARING, verify RTL sharing)
 DEFTIMEVAR (TV_REBUILD_FREQUENCIES   , 

[PATCH 05/27] New file: gcc/jit/config-lang.in

2014-10-31 Thread David Malcolm
gcc/jit/
* config-lang.in: New.
---
 gcc/jit/config-lang.in | 38 ++
 1 file changed, 38 insertions(+)
 create mode 100644 gcc/jit/config-lang.in

diff --git a/gcc/jit/config-lang.in b/gcc/jit/config-lang.in
new file mode 100644
index 000..7a32afe
--- /dev/null
+++ b/gcc/jit/config-lang.in
@@ -0,0 +1,38 @@
+# Top level configure fragment for libgccjit.so.
+#   Copyright (C) 2013-2014 Free Software Foundation, Inc.
+
+#This file is part of GCC.
+
+#GCC is free software; you can redistribute it and/or modify
+#it under the terms of the GNU General Public License as published by
+#the Free Software Foundation; either version 3, or (at your option)
+#any later version.
+
+#GCC is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# http://www.gnu.org/licenses/.
+
+# Configure looks for the existence of this file to auto-config each language.
+# We define several parameters used by configure:
+#
+# language - name of language as it would appear in $(LANGUAGES)
+# compilers- value to add to $(COMPILERS)
+
+language=jit
+
+compilers=libgccjit.so
+
+target_libs=
+
+gtfiles=\$(srcdir)/jit/dummy-frontend.c
+
+# The configuration requires --enable-host-shared
+# for jit to be supported.
+# Hence to get the jit, one must configure with:
+#   --enable-host-shared --enable-languages=jit
+build_by_default=no
-- 
1.8.5.3



[PATCH 22/27] Documentation: top-level index.rst

2014-10-31 Thread David Malcolm
The top-level index.rst provides the high-level structure for the
rest of the docs (which will follow in the patches that follow).

gcc/jit/ChangeLog:
* docs/index.rst: New.
---
 gcc/jit/docs/index.rst | 50 ++
 1 file changed, 50 insertions(+)
 create mode 100644 gcc/jit/docs/index.rst

diff --git a/gcc/jit/docs/index.rst b/gcc/jit/docs/index.rst
new file mode 100644
index 000..ed75e36
--- /dev/null
+++ b/gcc/jit/docs/index.rst
@@ -0,0 +1,50 @@
+.. Copyright (C) 2014 Free Software Foundation, Inc.
+   Originally contributed by David Malcolm dmalc...@redhat.com
+
+   This is free software: you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see
+   http://www.gnu.org/licenses/.
+
+libgccjit
+=
+
+Contents:
+
+.. toctree::
+   :maxdepth: 2
+
+   intro/index.rst
+   topics/index.rst
+   internals/index.rst
+
+This document describes `libgccjit http://gcc.gnu.org/wiki/JIT`_, an API
+for embedding GCC inside programs and libraries.
+
+Note that libgccjit is currently of Alpha quality;
+the APIs are not yet set in stone, and they shouldn't be used in
+production yet.
+
+
+Indices and tables
+==
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
+
+.. Some notes:
+
+   The Sphinx C domain appears to lack explicit support for enum values,
+   so I've been using :c:macro: for them.
+
+   See http://sphinx-doc.org/domains.html#the-c-domain
-- 
1.8.5.3



[PATCH 09/27] New file: gcc/jit/libgccjit.map

2014-10-31 Thread David Malcolm
This linker script ensures that the library only exports the symbols
we want it to.

gcc/jit/
* libgccjit.map: New.
---
 gcc/jit/libgccjit.map | 100 ++
 1 file changed, 100 insertions(+)
 create mode 100644 gcc/jit/libgccjit.map

diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map
new file mode 100644
index 000..d4ba7b6
--- /dev/null
+++ b/gcc/jit/libgccjit.map
@@ -0,0 +1,100 @@
+# Linker script for libgccjit.so
+#   Copyright (C) 2013-2014 Free Software Foundation, Inc.
+#   Contributed by David Malcolm dmalc...@redhat.com.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# http://www.gnu.org/licenses/.  */
+{
+  global:
+# Keep this list sorted alphabetically:
+gcc_jit_block_add_assignment;
+gcc_jit_block_add_assignment_op;
+gcc_jit_block_add_comment;
+gcc_jit_block_add_eval;
+gcc_jit_block_as_object;
+gcc_jit_block_end_with_conditional;
+gcc_jit_block_end_with_jump;
+gcc_jit_block_end_with_return;
+gcc_jit_block_end_with_void_return;
+gcc_jit_block_get_function;
+gcc_jit_context_acquire;
+gcc_jit_context_compile;
+gcc_jit_context_dump_to_file;
+gcc_jit_context_get_builtin_function;
+gcc_jit_context_get_first_error;
+gcc_jit_context_get_type;
+gcc_jit_context_get_int_type;
+gcc_jit_context_new_array_access;
+gcc_jit_context_new_array_type;
+gcc_jit_context_new_binary_op;
+gcc_jit_context_new_call;
+gcc_jit_context_new_call_through_ptr;
+gcc_jit_context_new_cast;
+gcc_jit_context_new_child_context;
+gcc_jit_context_new_comparison;
+gcc_jit_context_new_field;
+gcc_jit_context_new_function;
+gcc_jit_context_new_function_ptr_type;
+gcc_jit_context_new_global;
+gcc_jit_context_new_location;
+gcc_jit_context_new_opaque_struct;
+gcc_jit_context_new_param;
+gcc_jit_context_new_rvalue_from_double;
+gcc_jit_context_new_rvalue_from_int;
+gcc_jit_context_new_rvalue_from_ptr;
+gcc_jit_context_new_string_literal;
+gcc_jit_context_new_struct_type;
+gcc_jit_context_new_unary_op;
+gcc_jit_context_new_union_type;
+gcc_jit_context_null;
+gcc_jit_context_one;
+gcc_jit_context_release;
+gcc_jit_context_set_bool_option;
+gcc_jit_context_set_int_option;
+gcc_jit_context_set_str_option;
+gcc_jit_context_zero;
+gcc_jit_field_as_object;
+gcc_jit_function_as_object;
+gcc_jit_function_dump_to_dot;
+gcc_jit_function_get_param;
+gcc_jit_function_new_block;
+gcc_jit_function_new_local;
+gcc_jit_location_as_object;
+gcc_jit_lvalue_as_object;
+gcc_jit_lvalue_as_rvalue;
+gcc_jit_lvalue_access_field;
+gcc_jit_lvalue_get_address;
+gcc_jit_object_get_context;
+gcc_jit_object_get_debug_string;
+gcc_jit_param_as_lvalue;
+gcc_jit_param_as_object;
+gcc_jit_param_as_rvalue;
+gcc_jit_result_get_code;
+gcc_jit_result_release;
+gcc_jit_rvalue_access_field;
+gcc_jit_rvalue_as_object;
+gcc_jit_rvalue_dereference;
+gcc_jit_rvalue_dereference_field;
+gcc_jit_rvalue_get_type;
+gcc_jit_struct_as_type;
+gcc_jit_struct_set_fields;
+gcc_jit_type_as_object;
+gcc_jit_type_get_const;
+gcc_jit_type_get_pointer;
+gcc_jit_type_get_volatile;
+
+  local: *;
+};
\ No newline at end of file
-- 
1.8.5.3



[PATCH 20/27] Documentation: Makefile and conf.py

2014-10-31 Thread David Malcolm
When I previously submitted the jit for review, I posted all of the
documentation as one big patch, as:
  [PATCH 08/10] Documentation for the JIT library (Re: Patches 5-10 of jit 
merger)
https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01392.html

Since then, I've:

  * eliminated all mentions of pkg-config (since we no longer support
this)

  * eliminated the installation section and the discussion of packages

  * converted the final page (docs/internals/index.rst) into a short
guide for contributors to the project (e.g. myself and other
maintainers)

Prebuilt HTML from this can be seen at:
  https://dmalcolm.fedorapeople.org/gcc/libgccjit-api-docs/index.html

To make review easier, I've split the documentation up to smaller
patches, starting with this one.

This patch adds the Makefile and configuration file for Sphinx
for building docs from the .rst files that follow.

gcc/jit/
* docs/Makefile: New.
* docs/conf.py: New.
---
 gcc/jit/docs/Makefile | 153 ++
 gcc/jit/docs/conf.py  | 258 ++
 2 files changed, 411 insertions(+)
 create mode 100644 gcc/jit/docs/Makefile
 create mode 100644 gcc/jit/docs/conf.py

diff --git a/gcc/jit/docs/Makefile b/gcc/jit/docs/Makefile
new file mode 100644
index 000..7d20702
--- /dev/null
+++ b/gcc/jit/docs/Makefile
@@ -0,0 +1,153 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS=
+SPHINXBUILD   = sphinx-build
+PAPER =
+BUILDDIR  = _build
+
+# Internal variables.
+PAPEROPT_a4 = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp 
epub latex latexpdf text man changes linkcheck doctest gettext
+
+help:
+   @echo Please use \`make target' where target is one of
+   @echo   html   to make standalone HTML files
+   @echo   dirhtmlto make HTML files named index.html in directories
+   @echo   singlehtml to make a single large HTML file
+   @echo   pickle to make pickle files
+   @echo   json   to make JSON files
+   @echo   htmlhelp   to make HTML files and a HTML help project
+   @echo   qthelp to make HTML files and a qthelp project
+   @echo   devhelpto make HTML files and a Devhelp project
+   @echo   epub   to make an epub
+   @echo   latex  to make LaTeX files, you can set PAPER=a4 or 
PAPER=letter
+   @echo   latexpdf   to make LaTeX files and run them through pdflatex
+   @echo   text   to make text files
+   @echo   manto make manual pages
+   @echo   texinfoto make Texinfo files
+   @echo   info   to make Texinfo files and run them through makeinfo
+   @echo   gettextto make PO message catalogs
+   @echo   changesto make an overview of all changed/added/deprecated 
items
+   @echo   linkcheck  to check all external links for integrity
+   @echo   doctestto run all doctests embedded in the documentation 
(if enabled)
+
+clean:
+   -rm -rf $(BUILDDIR)/*
+
+html:
+   $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+   @echo
+   @echo Build finished. The HTML pages are in $(BUILDDIR)/html.
+
+dirhtml:
+   $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+   @echo
+   @echo Build finished. The HTML pages are in $(BUILDDIR)/dirhtml.
+
+singlehtml:
+   $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+   @echo
+   @echo Build finished. The HTML page is in $(BUILDDIR)/singlehtml.
+
+pickle:
+   $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+   @echo
+   @echo Build finished; now you can process the pickle files.
+
+json:
+   $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+   @echo
+   @echo Build finished; now you can process the JSON files.
+
+htmlhelp:
+   $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+   @echo
+   @echo Build finished; now you can run HTML Help Workshop with the \
+ .hhp project file in $(BUILDDIR)/htmlhelp.
+
+qthelp:
+   $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+   @echo
+   @echo Build finished; now you can run qcollectiongenerator with the 
\
+ .qhcp project file in $(BUILDDIR)/qthelp, like this:
+   @echo # qcollectiongenerator $(BUILDDIR)/qthelp/libgccjit.qhcp
+   @echo To view the help file:
+   @echo # assistant -collectionFile $(BUILDDIR)/qthelp/libgccjit.qhc
+
+devhelp:
+   $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+   @echo
+   @echo Build finished.
+

[PATCH 07/27] New file: gcc/jit/dummy-frontend.c

2014-10-31 Thread David Malcolm
gcc/jit/
* dummy-frontend.c: New.
---
 gcc/jit/dummy-frontend.c | 240 +++
 1 file changed, 240 insertions(+)
 create mode 100644 gcc/jit/dummy-frontend.c

diff --git a/gcc/jit/dummy-frontend.c b/gcc/jit/dummy-frontend.c
new file mode 100644
index 000..33f126f
--- /dev/null
+++ b/gcc/jit/dummy-frontend.c
@@ -0,0 +1,240 @@
+/* jit.c -- Dummy frontend for use during JIT-compilation.
+   Copyright (C) 2013-2014 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+http://www.gnu.org/licenses/.  */
+
+#include config.h
+#include system.h
+#include coretypes.h
+#include opts.h
+#include signop.h
+#include tree-core.h
+#include stor-layout.h
+#include tree.h
+#include debug.h
+#include langhooks.h
+#include langhooks-def.h
+#include cgraph.h
+
+#include jit-common.h
+#include jit-playback.h
+
+#include mpfr.h
+
+/* Language-dependent contents of a type.  */
+
+struct GTY(()) lang_type
+{
+  char dummy;
+};
+
+/* Language-dependent contents of a decl.  */
+
+struct GTY((variable_size)) lang_decl
+{
+  char dummy;
+};
+
+/* Language-dependent contents of an identifier.  This must include a
+   tree_identifier.  */
+
+struct GTY(()) lang_identifier
+{
+  struct tree_identifier common;
+};
+
+/* The resulting tree type.  */
+
+union GTY((desc (TREE_CODE (%h.generic) == IDENTIFIER_NODE),
+  chain_next (CODE_CONTAINS_STRUCT (TREE_CODE (%h.generic), 
TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (%h.generic)) : NULL)))
+lang_tree_node
+{
+  union tree_node GTY((tag (0),
+  desc (tree_node_structure (%h generic;
+  struct lang_identifier GTY((tag (1))) identifier;
+};
+
+/* We don't use language_function.  */
+
+struct GTY(()) language_function
+{
+  int dummy;
+};
+
+/* GC-marking callback for use from jit_root_tab.
+
+   If there's an active playback context, call its marking method
+   so that it can mark any pointers it references.  */
+
+static void my_ggc_walker (void *)
+{
+  if (gcc::jit::active_playback_ctxt)
+gcc::jit::active_playback_ctxt-gt_ggc_mx ();
+}
+
+const char *dummy;
+
+struct ggc_root_tab jit_root_tab[] =
+  {
+{
+  dummy, 1, 0, my_ggc_walker, NULL
+},
+LAST_GGC_ROOT_TAB
+  };
+
+/* Language hooks.  */
+
+static bool
+jit_langhook_init (void)
+{
+  static bool registered_root_tab = false;
+  if (!registered_root_tab)
+{
+  ggc_register_root_tab (jit_root_tab);
+  registered_root_tab = true;
+}
+
+  build_common_tree_nodes (false, false);
+
+  /* I don't know why this has to be done explicitly.  */
+  void_list_node = build_tree_list (NULL_TREE, void_type_node);
+
+  build_common_builtin_nodes ();
+
+  /* The default precision for floating point numbers.  This is used
+ for floating point constants with abstract type.  This may
+ eventually be controllable by a command line option.  */
+  mpfr_set_default_prec (256);
+
+  return true;
+}
+
+static void
+jit_langhook_parse_file (void)
+{
+  /* Replay the activity by the client, recorded on the context.  */
+  gcc_assert (gcc::jit::active_playback_ctxt);
+  gcc::jit::active_playback_ctxt-replay ();
+}
+
+static tree
+jit_langhook_type_for_mode (enum machine_mode mode, int unsignedp)
+{
+  if (mode == TYPE_MODE (float_type_node))
+return float_type_node;
+
+  if (mode == TYPE_MODE (double_type_node))
+return double_type_node;
+
+  if (mode == TYPE_MODE (integer_type_node))
+return unsignedp ? unsigned_type_node : integer_type_node;
+
+  if (mode == TYPE_MODE (long_integer_type_node))
+return unsignedp ? long_unsigned_type_node : long_integer_type_node;
+
+  if (COMPLEX_MODE_P (mode))
+{
+  if (mode == TYPE_MODE (complex_float_type_node))
+   return complex_float_type_node;
+  if (mode == TYPE_MODE (complex_double_type_node))
+   return complex_double_type_node;
+  if (mode == TYPE_MODE (complex_long_double_type_node))
+   return complex_long_double_type_node;
+  if (mode == TYPE_MODE (complex_integer_type_node)  !unsignedp)
+   return complex_integer_type_node;
+}
+
+  /* gcc_unreachable */
+  return NULL;
+}
+
+static tree
+jit_langhook_type_for_size (unsigned int bits ATTRIBUTE_UNUSED,
+   int unsignedp ATTRIBUTE_UNUSED)
+{
+  gcc_unreachable ();
+  return NULL;
+}
+
+/* Record a builtin function.  We just ignore builtin functions.  */
+
+static tree

[PATCH 06/27] New file: gcc/jit/Make-lang.in

2014-10-31 Thread David Malcolm
gcc/jit/
* Make-lang.in: New.
---
 gcc/jit/Make-lang.in | 298 +++
 1 file changed, 298 insertions(+)
 create mode 100644 gcc/jit/Make-lang.in

diff --git a/gcc/jit/Make-lang.in b/gcc/jit/Make-lang.in
new file mode 100644
index 000..167fcad
--- /dev/null
+++ b/gcc/jit/Make-lang.in
@@ -0,0 +1,298 @@
+# Top level -*- makefile -*- fragment for libgccjit.so.
+#   Copyright (C) 2013-2014 Free Software Foundation, Inc.
+
+#This file is part of GCC.
+
+#GCC is free software; you can redistribute it and/or modify
+#it under the terms of the GNU General Public License as published by
+#the Free Software Foundation; either version 3, or (at your option)
+#any later version.
+
+#GCC is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# http://www.gnu.org/licenses/.
+
+# This file provides the language dependent support in the main Makefile.
+# Each language makefile fragment must provide the following targets:
+#
+# foo.all.cross, foo.start.encap, foo.rest.encap,
+# foo.install-common, foo.install-man, foo.install-info, foo.install-pdf,
+# foo.install-html, foo.info, foo.dvi, foo.pdf, foo.html, foo.uninstall,
+# foo.mostlyclean, foo.clean, foo.distclean,
+# foo.maintainer-clean, foo.stage1, foo.stage2, foo.stage3, foo.stage4
+#
+# where `foo' is the name of the language.
+#
+# It should also provide rules for:
+#
+# - making any compiler driver (eg: g++)
+# - the compiler proper (eg: cc1plus)
+# - define the names for selecting the language in LANGUAGES.
+
+#
+# Define the names for selecting jit in LANGUAGES.
+# Note that it would be nice to move the dependency on g++
+# into the jit rule, but that needs a little bit of work
+# to do the right thing within all.cross.
+
+LIBGCCJIT_LINKER_NAME = libgccjit.so
+LIBGCCJIT_VERSION_NUM = 0
+LIBGCCJIT_MINOR_NUM = 0
+LIBGCCJIT_RELEASE_NUM = 1
+LIBGCCJIT_SONAME = $(LIBGCCJIT_LINKER_NAME).$(LIBGCCJIT_VERSION_NUM)
+LIBGCCJIT_FILENAME = \
+  $(LIBGCCJIT_SONAME).$(LIBGCCJIT_MINOR_NUM).$(LIBGCCJIT_RELEASE_NUM)
+
+LIBGCCJIT_LINKER_NAME_SYMLINK = $(LIBGCCJIT_LINKER_NAME)
+LIBGCCJIT_SONAME_SYMLINK = $(LIBGCCJIT_SONAME)
+
+jit: $(LIBGCCJIT_FILENAME) \
+   $(LIBGCCJIT_SYMLINK) \
+   $(LIBGCCJIT_LINKER_NAME_SYMLINK) \
+   $(FULL_DRIVER_NAME)
+
+# Tell GNU make to ignore these if they exist.
+.PHONY: jit
+
+jit_OBJS = attribs.o \
+   jit/dummy-frontend.o \
+   jit/libgccjit.o \
+   jit/jit-recording.o \
+   jit/jit-playback.o \
+   jit/jit-builtins.o
+
+# Use strict warnings for this front end.
+jit-warn = $(STRICT_WARN)
+
+# We avoid using $(BACKEND) from Makefile.in in order to avoid pulling
+# in main.o
+$(LIBGCCJIT_FILENAME): $(jit_OBJS) \
+   libbackend.a libcommon-target.a libcommon.a \
+   $(CPPLIB) $(LIBDECNUMBER) \
+   $(LIBDEPS) $(srcdir)/jit/libgccjit.map
+   +$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ -shared \
+$(jit_OBJS) libbackend.a libcommon-target.a libcommon.a \
+$(CPPLIB) $(LIBDECNUMBER) $(LIBS) $(BACKENDLIBS) \
+-Wl,--version-script=$(srcdir)/jit/libgccjit.map \
+-Wl,-soname,$(LIBGCCJIT_SONAME)
+
+$(LIBGCCJIT_SONAME_SYMLINK): $(LIBGCCJIT_FILENAME)
+   ln -sf $(LIBGCCJIT_FILENAME) $(LIBGCCJIT_SONAME_SYMLINK)
+
+$(LIBGCCJIT_LINKER_NAME_SYMLINK): $(LIBGCCJIT_SONAME_SYMLINK)
+   ln -sf $(LIBGCCJIT_SONAME_SYMLINK) $(LIBGCCJIT_LINKER_NAME_SYMLINK)
+
+#
+# Build hooks:
+
+jit.all.cross:
+jit.start.encap:
+jit.rest.encap:
+
+# Documentation build hooks.
+#
+# The documentation can be built using the texinfo toolchain, or
+# the sphinx toolchain
+#
+# The jit documentation is authored using Sphinx, which has numerous
+# advantages over Texinfo, including:
+#
+#   * much faster
+#
+#   * use of CSS and JS to provide less of a 1990s feel in the generated
+# HTML.
+#
+#   * sane, stable HTML page and anchor names
+#
+#   * sane HTML navigation: ability to move forward and back in the HTML
+# at every node to read the HTML like a book
+#
+#   * syntax-coloring of examples
+#
+#   * the ability to include fragments of code inline.  This is used
+# heavily by the jit docs, so that the example code is shared by both
+# the test suite and the documentation to ensure that the examples
+# appearing in the docs actually compile and work
+#
+# Sphinx is not a blessed dependency, and so a prebuilt libgccjit.texinfo
+# file built by Sphinx is checked into the source tree to avoid requiring
+# everyone to have Sphinx installed.
+#
+# This prebuilt libgccjit.texinfo has the include fragments baked in,
+# and so contains the content from the sphinx toolchain, but lacks the
+# syntax-coloring, and the generated 

[PATCH 21/27] Documentation: the examples subdirectory

2014-10-31 Thread David Malcolm
This patch adds examples.  These examples are used included
by the documentation when it is built, and are run as code by the
testsuite, ensuring that the examples shown in the docs build and
run.

gcc/jit/
* docs/examples/tut01-hello-world.c: New.
* docs/examples/tut02-square.c: New.
* docs/examples/tut03-sum-of-squares.c: New.
* docs/examples/tut04-toyvm/Makefile: New.
* docs/examples/tut04-toyvm/factorial.toy: New.
* docs/examples/tut04-toyvm/fibonacci.toy: New.
* docs/examples/tut04-toyvm/toyvm.c: New.
---
 gcc/jit/docs/examples/tut01-hello-world.c   | 123 
 gcc/jit/docs/examples/tut02-square.c| 107 +++
 gcc/jit/docs/examples/tut03-sum-of-squares.c| 172 +
 gcc/jit/docs/examples/tut04-toyvm/Makefile  |  11 +
 gcc/jit/docs/examples/tut04-toyvm/factorial.toy |  50 ++
 gcc/jit/docs/examples/tut04-toyvm/fibonacci.toy |  66 ++
 gcc/jit/docs/examples/tut04-toyvm/toyvm.c   | 861 
 7 files changed, 1390 insertions(+)
 create mode 100644 gcc/jit/docs/examples/tut01-hello-world.c
 create mode 100644 gcc/jit/docs/examples/tut02-square.c
 create mode 100644 gcc/jit/docs/examples/tut03-sum-of-squares.c
 create mode 100644 gcc/jit/docs/examples/tut04-toyvm/Makefile
 create mode 100644 gcc/jit/docs/examples/tut04-toyvm/factorial.toy
 create mode 100644 gcc/jit/docs/examples/tut04-toyvm/fibonacci.toy
 create mode 100644 gcc/jit/docs/examples/tut04-toyvm/toyvm.c

diff --git a/gcc/jit/docs/examples/tut01-hello-world.c 
b/gcc/jit/docs/examples/tut01-hello-world.c
new file mode 100644
index 000..49c9651
--- /dev/null
+++ b/gcc/jit/docs/examples/tut01-hello-world.c
@@ -0,0 +1,123 @@
+/* Smoketest example for libgccjit.so
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+http://www.gnu.org/licenses/.  */
+
+#include libgccjit.h
+
+#include stdlib.h
+#include stdio.h
+
+static void
+create_code (gcc_jit_context *ctxt)
+{
+  /* Let's try to inject the equivalent of:
+ void
+ greet (const char *name)
+ {
+printf (hello %s\n, name);
+ }
+  */
+  gcc_jit_type *void_type =
+gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
+  gcc_jit_type *const_char_ptr_type =
+gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CONST_CHAR_PTR);
+  gcc_jit_param *param_name =
+gcc_jit_context_new_param (ctxt, NULL, const_char_ptr_type, name);
+  gcc_jit_function *func =
+gcc_jit_context_new_function (ctxt, NULL,
+  GCC_JIT_FUNCTION_EXPORTED,
+  void_type,
+  greet,
+  1, param_name,
+  0);
+
+  gcc_jit_param *param_format =
+gcc_jit_context_new_param (ctxt, NULL, const_char_ptr_type, format);
+  gcc_jit_function *printf_func =
+gcc_jit_context_new_function (ctxt, NULL,
+ GCC_JIT_FUNCTION_IMPORTED,
+ gcc_jit_context_get_type (
+ctxt, GCC_JIT_TYPE_INT),
+ printf,
+ 1, param_format,
+ 1);
+  gcc_jit_rvalue *args[2];
+  args[0] = gcc_jit_context_new_string_literal (ctxt, hello %s\n);
+  args[1] = gcc_jit_param_as_rvalue (param_name);
+
+  gcc_jit_block *block = gcc_jit_function_new_block (func, NULL);
+
+  gcc_jit_block_add_eval (
+block, NULL,
+gcc_jit_context_new_call (ctxt,
+  NULL,
+  printf_func,
+  2, args));
+  gcc_jit_block_end_with_void_return (block, NULL);
+}
+
+int
+main (int argc, char **argv)
+{
+  gcc_jit_context *ctxt;
+  gcc_jit_result *result;
+
+  /* Get a context object for working with the library.  */
+  ctxt = gcc_jit_context_acquire ();
+  if (!ctxt)
+{
+  fprintf (stderr, NULL ctxt);
+  exit (1);
+}
+
+  /* Set some options on the context.
+ Let's see the code being generated, in assembler form.  */
+  gcc_jit_context_set_bool_option (
+ctxt,
+GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE,
+0);
+
+  /* Populate the context.  */
+  create_code (ctxt);
+
+  /* Compile the code.  */
+  result = gcc_jit_context_compile (ctxt);
+  if (!result)
+{
+  fprintf (stderr, NULL result);
+  exit (1);
+

[PATCH 23/27] Documentation: the intro subdirectory

2014-10-31 Thread David Malcolm
The intro subdirectory of gcc/jit/docs consists of a 4-part tutorial
aimed at experienced developers who are new users of the library, taking
them from beginning use all the way up to adding JIT-compilation to an
interpreter.

gcc/jit/
* docs/intro/factorial.png: New.
* docs/intro/index.rst: New.
* docs/intro/sum-of-squares.png: New.
* docs/intro/tutorial01.rst: New.
* docs/intro/tutorial02.rst: New.
* docs/intro/tutorial03.rst: New.
* docs/intro/tutorial04.rst: New.
---
 gcc/jit/docs/intro/factorial.png  |  Bin 0 - 183838 bytes
 gcc/jit/docs/intro/index.rst  |   27 +
 gcc/jit/docs/intro/sum-of-squares.png |  Bin 0 - 22839 bytes
 gcc/jit/docs/intro/tutorial01.rst |   52 ++
 gcc/jit/docs/intro/tutorial02.rst |  349 +++
 gcc/jit/docs/intro/tutorial03.rst |  378 +++
 gcc/jit/docs/intro/tutorial04.rst | 1108 +
 7 files changed, 1914 insertions(+)
 create mode 100644 gcc/jit/docs/intro/factorial.png
 create mode 100644 gcc/jit/docs/intro/index.rst
 create mode 100644 gcc/jit/docs/intro/sum-of-squares.png
 create mode 100644 gcc/jit/docs/intro/tutorial01.rst
 create mode 100644 gcc/jit/docs/intro/tutorial02.rst
 create mode 100644 gcc/jit/docs/intro/tutorial03.rst
 create mode 100644 gcc/jit/docs/intro/tutorial04.rst

diff --git a/gcc/jit/docs/intro/factorial.png b/gcc/jit/docs/intro/factorial.png
new file mode 100644
index 000..dff47ce
Binary files /dev/null and b/gcc/jit/docs/intro/factorial.png differ
diff --git a/gcc/jit/docs/intro/index.rst b/gcc/jit/docs/intro/index.rst
new file mode 100644
index 000..d3bcec9
--- /dev/null
+++ b/gcc/jit/docs/intro/index.rst
@@ -0,0 +1,27 @@
+.. Copyright (C) 2014 Free Software Foundation, Inc.
+   Originally contributed by David Malcolm dmalc...@redhat.com
+
+   This is free software: you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see
+   http://www.gnu.org/licenses/.
+
+Tutorial
+
+
+.. toctree::
+   :maxdepth: 2
+
+   tutorial01.rst
+   tutorial02.rst
+   tutorial03.rst
+   tutorial04.rst
diff --git a/gcc/jit/docs/intro/sum-of-squares.png 
b/gcc/jit/docs/intro/sum-of-squares.png
new file mode 100644
index 000..7a3b4af
Binary files /dev/null and b/gcc/jit/docs/intro/sum-of-squares.png differ
diff --git a/gcc/jit/docs/intro/tutorial01.rst 
b/gcc/jit/docs/intro/tutorial01.rst
new file mode 100644
index 000..b1a5128
--- /dev/null
+++ b/gcc/jit/docs/intro/tutorial01.rst
@@ -0,0 +1,52 @@
+.. Copyright (C) 2014 Free Software Foundation, Inc.
+   Originally contributed by David Malcolm dmalc...@redhat.com
+
+   This is free software: you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see
+   http://www.gnu.org/licenses/.
+
+.. default-domain:: c
+
+Tutorial part 1: Hello world
+==
+
+Before we look at the details of the API, let's look at building and
+running programs that use the library.
+
+Here's a toy hello world program that uses the library to synthesize
+a call to `printf` and uses it to write a message to stdout.
+
+Don't worry about the content of the program for now; we'll cover
+the details in later parts of this tutorial.
+
+   .. literalinclude:: ../examples/tut01-hello-world.c
+:language: c
+
+Copy the above to `tut01-hello-world.c`.
+
+Assuming you have the jit library installed, build the test program
+using:
+
+.. code-block:: console
+
+  $ gcc \
+  tut01-hello-world.c \
+  -o tut01-hello-world \
+  -lgccjit
+
+You should then be able to run the built program:
+
+.. code-block:: console
+
+  $ ./tut01-hello-world
+  hello world
diff --git a/gcc/jit/docs/intro/tutorial02.rst 
b/gcc/jit/docs/intro/tutorial02.rst
new file mode 100644
index 000..f52499e
--- /dev/null
+++ b/gcc/jit/docs/intro/tutorial02.rst
@@ -0,0 +1,349 @@
+.. Copyright (C) 2014 Free Software Foundation, Inc.
+   Originally contributed by David 

Re: [Patch, testsuite] [AArch64,ARM] support bswap tests on aarch64_be

2014-10-31 Thread Ramana Radhakrishnan
On Wed, Oct 29, 2014 at 1:22 PM, Christophe Lyon
christophe.l...@linaro.org wrote:
 Hi,

 Following discussions after Thomas's patches improving bswap support
 https://gcc.gnu.org/ml/gcc-patches/2014-09/msg01279.html

 I noticed that:
 * the associated tests weren't executed on aarch64_be
 * ARM targets older than v6 do not support the needed instructions.

 The attached patch changes check_effective_target_bswap():
 - accept aarch64*-*-* instead of aarch64-*-*
 - when target is arm*-*-*, check __ARM_ARCH = 6

 2014-10-29  Christophe Lyon  christophe.l...@linaro.org

 * lib/target-supports.exp (check_effective_target_bswap): Update
 conditions for AArch64 and ARM targets.

 OK?

The ARM (AArch32) changes are ok.

Ramana


 Christophe.


Re: [patch] flatten/adjust optabs.h

2014-10-31 Thread Jeff Law

On 10/30/14 09:42, Andrew MacLeod wrote:

This patch adjusts optabs.h.  which was really sub-work of looking at
expr.h.

I moved the prototypes from expr.h to optabs.h that belong there, and
realigned the stuff in optabs.h to be in the same order as the .c file.
I also moved gen_move_insn from optabs.c to expr.c... a number of new
files would have required optabs.h to compile just for that funciton,
and gen_move_insn primarily calls emit-move_insn_1 which is defined in
expr.c anyway.. so it makes sense to be there.

the one thing Im on the fence about is insn-opinit.h.   This is *only*
included from optabs.h, so I am inclined to leave it as an include from
optabs.h.  We'd likely just be putting it back there later anyway.

I also moved the first section of optabs.h into genopinit.c... that
contains the parts which define structures, prototypes and a couple of
small inlines for things in insn-opinit.c.. so I figured we may as well
may insn-opinit.h follow the same pattern and list the exports and such
for insn-opinit.c.Now, ultimately I don't feel strongly about that
since insn-opinit.h is always included from optabs.h...  if someone
objects I can move them back out of the generated file.

Other than that, its just more header adjustments.

bootstraps on x86_64-unknown-linux-gnu, testsuite regressions a re
running (I expect none again) and I'll ruin it through a full set of
targets from contrib/config-list.mk.
Assuming no issues, ok for trunk?

Andrew


optab1.patch


* optabs.h: Flatten insn-codes.h to source files.  Move some prototypes
and structs to genopinit.c.  Adjust protyoptypes to match optabs.c.
* genopinit.c (main): Emit prototypes and structs into insn-opinit.h.
* optabs.c: (gen_move_insn): Move to expr.c.
* expr.h: Move protypes and enums to optabs.h.
* expr.c: (gen_move_insn): Relocate from optabs.c.
* genemit.c (main): Include insn-codes.h.
* gengtype.c (open_base_files): Include insn-codes.h.
OK.  No strong feelings on the insn-opinit issue and it'd be easy to 
change it if we want to do something different.


Maybe you've hit on a reasonable exception to the general rule of not 
including other files in a .h file.  I doubt we'd really know until 
we're further along in this process.


Jeff


Re: ptx preliminary rtl patches [1/4]

2014-10-31 Thread Bernd Schmidt

On 10/30/2014 06:36 PM, Segher Boessenkool wrote:

On Thu, Sep 11, 2014 at 03:24:54PM +0200, Bernd Schmidt wrote:

The nvptx backend is somewhat unusual in that call insns set a pseudo.
The combiner is surprised by this and allows combining them into other
insns, which remain as INSN rather than CALL_INSN. Aborts ensue.


distribute_notes has code for when I2 is a CALL.  This suggests that
on some other targets there can be useful combinations made, so it
isn't in that case terribly nice to disable all combinations with CALLs
as I0 or I1 or I2.

Or it's dead code :-)


I suspect the latter. As far as I can tell the patch does not change 
code generation on x86_64 at least (on a large set of input files 
including gcc, spec2k and linux-kernel).



Bernd




Re: [PATCH, ifcvt] Check size cost in noce_try_store_flag_mask

2014-10-31 Thread Jeff Law

On 10/31/14 00:30, Zhenqiang Chen wrote:

Thank you all for the comments. Patch is updated.

Bootstrap and no make check regression on X86-64.
No make check regression with Cortex-M0 qemu.
No performance changes for coremark, dhrystone, spec2000 and spec2006 on
X86-64 and Cortex-A15.

For CSiBE, ARM Cortex-M0 result is a little better. A little regression for
MIPS (less than 0.01%).
Given Matthew's follow-up indicting he was comfortable with the patch 
as-is and the MIPS folks will follow-up on their costing models, this 
patch is fine.


jeff



[PATCH 11/27] New file: gcc/jit/jit-common.h

2014-10-31 Thread David Malcolm
This header has forward declarations of both the jit::recording
and jit::playback internal APIs.

gcc/jit/
* jit-common.h: New.
---
 gcc/jit/jit-common.h | 182 +++
 1 file changed, 182 insertions(+)
 create mode 100644 gcc/jit/jit-common.h

diff --git a/gcc/jit/jit-common.h b/gcc/jit/jit-common.h
new file mode 100644
index 000..58e4a8c
--- /dev/null
+++ b/gcc/jit/jit-common.h
@@ -0,0 +1,182 @@
+/* Core of implementation of libgccjit.so
+   Copyright (C) 2013-2014 Free Software Foundation, Inc.
+   Contributed by David Malcolm dmalc...@redhat.com.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+http://www.gnu.org/licenses/.  */
+
+#ifndef JIT_COMMON_H
+#define JIT_COMMON_H
+
+#include libgccjit.h
+
+#include tree.h
+#include tree-iterator.h
+
+#ifdef GCC_VERSION
+#if GCC_VERSION = 4001
+#define GNU_PRINTF(M, N) __attribute__ ((format (gnu_printf, (M), (N
+#else
+#define GNU_PRINTF(M, N)
+#endif
+#endif
+
+const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_FILE_PTR + 1;
+
+/* This comment is included by the docs.
+
+   In order to allow jit objects to be usable outside of a compile
+   whilst working with the existing structure of GCC's code the
+   C API is implemented in terms of a gcc::jit::recording::context,
+   which records the calls made to it.
+
+   When a gcc_jit_context is compiled, the recording context creates a
+   playback context.  The playback context invokes the bulk of the GCC
+   code, and within the frontend parsing hook, plays back the recorded
+   API calls, creating GCC tree objects.
+
+   So there are two parallel families of classes: those relating to
+   recording, and those relating to playback:
+
+   * Visibility: recording objects are exposed back to client code,
+ whereas playback objects are internal to the library.
+
+   * Lifetime: recording objects have a lifetime equal to that of the
+ recording context that created them, whereas playback objects only
+ exist within the frontend hook.
+
+   * Memory allocation: recording objects are allocated by the recording
+ context, and automatically freed by it when the context is released,
+ whereas playback objects are allocated within the GC heap, and
+ garbage-collected; they can own GC-references.
+
+   * Integration with rest of GCC: recording objects are unrelated to the
+ rest of GCC, whereas playback objects are wrappers around tree
+ instances.  Hence you can't ask a recording rvalue or lvalue what its
+ type is, whereas you can for a playback rvalue of lvalue (since it
+ can work with the underlying GCC tree nodes).
+
+   * Instancing: There can be multiple recording contexts alive at once
+ (albeit it only one compiling at once), whereas there can only be one
+ playback context alive at one time (since it interacts with the GC).
+
+   Ultimately if GCC could support multiple GC heaps and contexts, and
+   finer-grained initialization, then this recording vs playback
+   distinction could be eliminated.
+
+   During a playback, we associate objects from the recording with
+   their counterparts during this playback.  For simplicity, we store this
+   within the recording objects, as ``void *m_playback_obj``, casting it to
+   the appropriate playback object subclass.  For these casts to make
+   sense, the two class hierarchies need to have the same structure.
+
+   Note that the playback objects that ``m_playback_obj`` points to are
+   GC-allocated, but the recording objects don't own references:
+   these associations only exist within a part of the code where
+   the GC doesn't collect, and are set back to NULL before the GC can
+   run.
+
+   End of comment for inclusion in the docs.  */
+
+namespace gcc {
+
+namespace jit {
+
+class result;
+class dump;
+
+namespace recording {
+
+  /* Recording types.  */
+
+  /* Indentation indicates inheritance: */
+  class context;
+  class builtins_manager; // declared within jit-builtins.h
+  class memento;
+class string;
+class location;
+class type;
+  class function_type;
+  class compound_type;
+class struct_;
+   class union_;
+class field;
+class fields;
+class function;
+class block;
+class rvalue;
+  class lvalue;
+class local;
+   class global;
+class param;
+class statement;
+
+  /* End of recording types. */
+}
+
+namespace playback {
+  /* 

[PATCH 10/27] New file: gcc/jit/libgccjit.c

2014-10-31 Thread David Malcolm
This file implements the entrypoints of the library's public API.

It performs error-checking at this boundary, before calling into the
jit-recording.h internal API.

gcc/jit/
* libgccjit.c: New.
---
 gcc/jit/libgccjit.c | 1506 +++
 1 file changed, 1506 insertions(+)
 create mode 100644 gcc/jit/libgccjit.c

diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
new file mode 100644
index 000..286a85e
--- /dev/null
+++ b/gcc/jit/libgccjit.c
@@ -0,0 +1,1506 @@
+/* Implementation of the C API; all wrappers into the internal C++ API
+   Copyright (C) 2013-2014 Free Software Foundation, Inc.
+   Contributed by David Malcolm dmalc...@redhat.com.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+http://www.gnu.org/licenses/.  */
+
+#include config.h
+#include system.h
+#include coretypes.h
+#include opts.h
+
+#include libgccjit.h
+#include jit-common.h
+#include jit-recording.h
+
+#define IS_ASCII_ALPHA(CHAR) \
+  (\
+((CHAR) = 'a'  (CHAR) ='z')\
+|| \
+((CHAR) = 'A'  (CHAR) = 'Z')   \
+  )
+
+#define IS_ASCII_DIGIT(CHAR) \
+  ((CHAR) = '0'  (CHAR) ='9')
+
+#define IS_ASCII_ALNUM(CHAR) \
+  (IS_ASCII_ALPHA (CHAR) || IS_ASCII_DIGIT (CHAR))
+
+struct gcc_jit_context : public gcc::jit::recording::context
+{
+  gcc_jit_context (gcc_jit_context *parent_ctxt) :
+context (parent_ctxt)
+  {}
+};
+
+struct gcc_jit_result : public gcc::jit::result
+{
+};
+
+struct gcc_jit_object : public gcc::jit::recording::memento
+{
+};
+
+struct gcc_jit_location : public gcc::jit::recording::location
+{
+};
+
+struct gcc_jit_type : public gcc::jit::recording::type
+{
+};
+
+struct gcc_jit_struct : public gcc::jit::recording::struct_
+{
+};
+
+struct gcc_jit_field : public gcc::jit::recording::field
+{
+};
+
+struct gcc_jit_function : public gcc::jit::recording::function
+{
+};
+
+struct gcc_jit_block : public gcc::jit::recording::block
+{
+};
+
+struct gcc_jit_rvalue : public gcc::jit::recording::rvalue
+{
+};
+
+struct gcc_jit_lvalue : public gcc::jit::recording::lvalue
+{
+};
+
+struct gcc_jit_param : public gcc::jit::recording::param
+{
+};
+
+/**
+ Error-handling.
+
+ We try to gracefully handle API usage errors by being defensive
+ at the API boundary.
+ **/
+
+#define JIT_BEGIN_STMT do {
+#define JIT_END_STMT   } while(0)
+
+/* TODO: mark failure branches as unlikely? */
+
+#define RETURN_VAL_IF_FAIL(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_MSG) \
+  JIT_BEGIN_STMT   \
+if (!(TEST_EXPR))  \
+  {\
+   jit_error ((CTXT), (LOC), %s: %s, __func__, (ERR_MSG));   \
+   return (RETURN_EXPR);   \
+  }\
+  JIT_END_STMT
+
+#define RETURN_VAL_IF_FAIL_PRINTF1(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, 
A0) \
+  JIT_BEGIN_STMT   \
+if (!(TEST_EXPR))  \
+  {\
+   jit_error ((CTXT), (LOC), %s:  ERR_FMT,   \
+  __func__, (A0)); \
+   return (RETURN_EXPR);   \
+  }\
+  JIT_END_STMT
+
+#define RETURN_VAL_IF_FAIL_PRINTF2(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, 
A0, A1) \
+  JIT_BEGIN_STMT   \
+if (!(TEST_EXPR))  \
+  {\
+   jit_error ((CTXT), (LOC), %s:  ERR_FMT,   
\
+  __func__, (A0), (A1));   \
+   return (RETURN_EXPR);   \
+  }\
+  JIT_END_STMT
+
+#define RETURN_VAL_IF_FAIL_PRINTF3(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, 
A0, A1, 

[PATCH 12/27] New file: gcc/jit/jit-recording.h

2014-10-31 Thread David Malcolm
This file declares the gcc::jit::recording internal API, so that
libgccjit.c can record the calls that are made to the public API, for
later playback by the dummy frontend.

gcc/jit/
* jit-recording.h: New.
---
 gcc/jit/jit-recording.h | 1593 +++
 1 file changed, 1593 insertions(+)
 create mode 100644 gcc/jit/jit-recording.h

diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
new file mode 100644
index 000..bb1a2ee
--- /dev/null
+++ b/gcc/jit/jit-recording.h
@@ -0,0 +1,1593 @@
+/* Internals of libgccjit: classes for recording calls made to the JIT API.
+   Copyright (C) 2013-2014 Free Software Foundation, Inc.
+   Contributed by David Malcolm dmalc...@redhat.com.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+http://www.gnu.org/licenses/.  */
+
+#ifndef JIT_RECORDING_H
+#define JIT_RECORDING_H
+
+#include jit-common.h
+
+namespace gcc {
+
+namespace jit {
+
+class result;
+class dump;
+
+/**
+ Recording.
+ **/
+
+namespace recording {
+
+playback::location *
+playback_location (replayer *r, location *loc);
+
+const char *
+playback_string (string *str);
+
+playback::block *
+playback_block (block *b);
+
+/* A JIT-compilation context.  */
+class context
+{
+public:
+  context (context *parent_ctxt);
+  ~context ();
+
+  void record (memento *m);
+  void replay_into (replayer *r);
+  void disassociate_from_playback ();
+
+  string *
+  new_string (const char *text);
+
+  location *
+  new_location (const char *filename,
+   int line,
+   int column);
+
+  type *
+  get_type (enum gcc_jit_types type);
+
+  type *
+  get_int_type (int num_bytes, int is_signed);
+
+  type *
+  new_array_type (location *loc,
+ type *element_type,
+ int num_elements);
+
+  field *
+  new_field (location *loc,
+type *type,
+const char *name);
+
+  struct_ *
+  new_struct_type (location *loc,
+  const char *name);
+
+  union_ *
+  new_union_type (location *loc,
+ const char *name);
+
+  type *
+  new_function_ptr_type (location *loc,
+type *return_type,
+int num_params,
+type **param_types,
+int is_variadic);
+
+  param *
+  new_param (location *loc,
+type *type,
+const char *name);
+
+  function *
+  new_function (location *loc,
+   enum gcc_jit_function_kind kind,
+   type *return_type,
+   const char *name,
+   int num_params,
+   param **params,
+   int is_variadic,
+   enum built_in_function builtin_id);
+
+  function *
+  get_builtin_function (const char *name);
+
+  lvalue *
+  new_global (location *loc,
+ type *type,
+ const char *name);
+
+  rvalue *
+  new_rvalue_from_int (type *numeric_type,
+  int value);
+
+  rvalue *
+  new_rvalue_from_double (type *numeric_type,
+ double value);
+
+  rvalue *
+  new_rvalue_from_ptr (type *pointer_type,
+  void *value);
+
+  rvalue *
+  new_string_literal (const char *value);
+
+  rvalue *
+  new_unary_op (location *loc,
+   enum gcc_jit_unary_op op,
+   type *result_type,
+   rvalue *a);
+
+  rvalue *
+  new_binary_op (location *loc,
+enum gcc_jit_binary_op op,
+type *result_type,
+rvalue *a, rvalue *b);
+
+  rvalue *
+  new_comparison (location *loc,
+ enum gcc_jit_comparison op,
+ rvalue *a, rvalue *b);
+
+  rvalue *
+  new_call (location *loc,
+   function *func,
+   int numargs, rvalue **args);
+
+  rvalue *
+  new_call_through_ptr (location *loc,
+   rvalue *fn_ptr,
+   int numargs, rvalue **args);
+
+  rvalue *
+  new_cast (location *loc,
+   rvalue *expr,
+   type *type_);
+
+  lvalue *
+  new_array_access (location *loc,
+   rvalue *ptr,
+   rvalue *index);
+
+  void
+  set_str_option (enum gcc_jit_str_option opt,
+ const char *value);
+
+  void
+  set_int_option (enum gcc_jit_int_option opt,
+

[PATCH 18/27] New file: gcc/jit/TODO.rst

2014-10-31 Thread David Malcolm
This is a list of TODOs for working on the JIT.

gcc/jit/
* TODO.rst: New.
---
 gcc/jit/TODO.rst | 119 +++
 1 file changed, 119 insertions(+)
 create mode 100644 gcc/jit/TODO.rst

diff --git a/gcc/jit/TODO.rst b/gcc/jit/TODO.rst
new file mode 100644
index 000..09c4d9d
--- /dev/null
+++ b/gcc/jit/TODO.rst
@@ -0,0 +1,119 @@
+TODOs
+-
+
+API
+===
+* error-handling:
+* have a client-provided error-handling callback for the context, and
+  call it, rather than asserting/crashing etc, to make the API resilient 
and helpful
+
+* probably should turn off signal handlers and backtracing, leaving that to
+  the client code
+
+* enums and ABI: give enums specific numbers, in ranges, to make it
+  possible to maintain a logical ordering whilst preserving ABI.
+
+* expose the statements in the API? (mostly so they can be stringified?)
+
+* support more arithmetic ops and comparison modes
+
+* access to a function by address::
+
+extern gcc_jit_function *
+gcc_jit_context_get_function (ctxt,
+  void *); /* need type information */
+
+  so you can access static fns in your code.
+
+* ability to turn a function into a function pointer::
+
+gcc_jit_function_as_rvalue ()
+
+* expressing branch probabilies (like __builtin_expect)::
+
+extern gcc_jit_rvalue *
+gcc_jit_rvalue_likely (gcc_jit_rvalue *rvalue,
+   int is_likely);
+
+  though would:
+
+extern void
+gcc_jit_block_set_likelihood (gcc_jit_block *block,
+  int hotness);
+
+  be better?  (for expressing how hot the current location is)
+
+* add a SONAME to the library (and potentially version the symbols?)
+
+* do we need alternative forms of division (floor vs rounding)?
+
+* are we missing any ops?
+
+* error-checking:
+
+* gcc_jit_context_new_unary_op: various checks needed
+
+* gcc_jit_context_new_binary_op: various checks needed
+
+* gcc_jit_context_new_comparison: must be numeric or pointer types
+
+* gcc_jit_context_new_array_access: index must be of numeric type.
+
+* gcc_jit_lvalue_access_field: must be field of correct struct
+
+* gcc_jit_rvalue_access_field: must be field of correct struct
+
+* gcc_jit_block_add_assignment_op: check the types
+
+* Implement more kinds of casts e.g. pointers
+
+Bugs
+
+* fixing all the state issues: make it work repeatedly with optimization
+  turned up to full.
+
+* make the dirty dirty hacks less egregious...
+
+* test under valgrind; fix memory leaks
+
+* re-architect gcc so we don't have to reinitialize everything every time
+  a context is compiled
+
+Test suite
+==
+* get DejaGnu to build and run C++ testcases
+
+* measure code coverage in testing of libgccjit.so
+
+Future milestones
+=
+* try porting llvmpipe to gcc
+
+* inline assembler?
+
+* Detect and issue warnings/errors about uses of uninitialized variables
+
+* Warn about unused objects in a context (e.g. rvalues/lvalues)?  (e.g.
+  for gcc_jit_context_new_call vs gcc_jit_block_add_eval)
+
+Nice to have
+
+* Currently each function has a single stmt_list, which is built in
+  postprocessing by walking the list of blocks.  Presumably we could
+  have each block have its own stmt_list, avoiding the need for this
+  traversal, and having the block structure show up within tree dumps.
+  Alternatively, could we skip tree and go straight to gimple?
+
+* ability to give contexts names, for ease of debugging?
+
+
+Probably not needed
+===
+* switch and case ?
+
+* sizeof (should this be an API hook?)  do we even need it? presumably
+  client code can just do the sizeof() in its own code.
+
+* do we need unary plus?
+
+etc etc
-- 
1.8.5.3



[PATCH 14/27] New files: gcc/jit/jit-builtins.{c|h}

2014-10-31 Thread David Malcolm
These files implement support for builtins, for the
  gcc_jit_context_get_builtin_function
API entrypoint.

Only a subset of builtins are currently supported, based on those
that I needed when porting GNU Octave's JIT.

Attempts to use other builtins may lead to an error:
  unimplemented primitive type for builtin
being emitted on the gcc_jit_context.

gcc/jit/
* jit-builtins.c: New.
* jit-builtins.h: New.
---
 gcc/jit/jit-builtins.c | 424 +
 gcc/jit/jit-builtins.h | 114 +
 2 files changed, 538 insertions(+)
 create mode 100644 gcc/jit/jit-builtins.c
 create mode 100644 gcc/jit/jit-builtins.h

diff --git a/gcc/jit/jit-builtins.c b/gcc/jit/jit-builtins.c
new file mode 100644
index 000..07902e8
--- /dev/null
+++ b/gcc/jit/jit-builtins.c
@@ -0,0 +1,424 @@
+/* jit-builtins.c -- Handling of builtin functions during JIT-compilation.
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+http://www.gnu.org/licenses/.  */
+
+#include config.h
+#include system.h
+#include coretypes.h
+#include opts.h
+#include tree.h
+#include target.h
+
+#include jit-common.h
+#include jit-builtins.h
+#include jit-recording.h
+
+namespace gcc {
+
+namespace jit {
+
+namespace recording {
+
+const char *const prefix = __builtin_;
+const size_t prefix_len = strlen (prefix);
+
+/* Create builtin_data, a const table of the data within builtins.def.  */
+struct builtin_data
+{
+  const char *name;
+  enum jit_builtin_type type;
+  bool both_p;
+  bool fallback_p;
+
+  const char *get_asm_name () const
+  {
+if (both_p  fallback_p)
+  return name + prefix_len;
+else
+  return name;
+  }
+};
+
+#define DEF_BUILTIN(X, NAME, C, TYPE, LT, BOTH_P, FALLBACK_P, NA, AT, IM, 
COND)\
+  {NAME, TYPE, BOTH_P, FALLBACK_P},
+static const struct builtin_data builtin_data[] =
+{
+#include builtins.def
+};
+#undef DEF_BUILTIN
+
+/* Helper function for find_builtin_by_name.  */
+
+static bool
+matches_builtin (const char *in_name,
+const struct builtin_data bd)
+{
+  const bool debug = 0;
+  gcc_assert (bd.name);
+
+  if (debug)
+fprintf (stderr, seen builtin: %s\n, bd.name);
+
+  if (0 == strcmp (bd.name, in_name))
+{
+  return true;
+}
+
+  if (bd.both_p)
+{
+  /* Then the macros in builtins.def gave a __builtin_
+prefix to bd.name, but we should also recognize the form
+without the prefix.  */
+  gcc_assert (0 == strncmp (bd.name, prefix, prefix_len));
+  if (debug)
+   fprintf (stderr, testing without prefix as: %s\n,
+bd.name + prefix_len);
+  if (0 == strcmp (bd.name + prefix_len, in_name))
+   {
+ return true;
+   }
+}
+
+  return false;
+}
+
+/* Locate the built-in function that matches name IN_NAME,
+   writing the result to OUT_ID and returning true if found,
+   or returning false if not found.  */
+
+static bool
+find_builtin_by_name (const char *in_name,
+ enum built_in_function *out_id)
+{
+  /* Locate builtin.  This currently works by performing repeated
+ strcmp against every possible candidate, which is likely to
+ inefficient.
+
+ We start at index 1 to skip the initial entry (BUILT_IN_NONE), which
+ has a NULL name.  */
+  for (unsigned int i = 1;
+   i  sizeof (builtin_data) / sizeof (builtin_data[0]);
+   i++)
+{
+  const struct builtin_data bd = builtin_data[i];
+  if (matches_builtin (in_name, bd))
+   {
+ /* Found a match.  */
+ *out_id = static_castenum built_in_function (i);
+ return true;
+   }
+}
+
+  /* Not found.  */
+  return false;
+}
+
+// class builtins_manager
+
+/* Constructor for gcc::jit::recording::builtins_manager.  */
+
+builtins_manager::builtins_manager (context *ctxt)
+  : m_ctxt (ctxt)
+{
+  memset (m_types, 0, sizeof (m_types));
+  memset (m_builtin_functions, 0, sizeof (m_builtin_functions));
+}
+
+/* Locate a builtin function by name.
+   Create a recording::function of the appropriate type, reusing them
+   if they've already been seen.  */
+
+function *
+builtins_manager::get_builtin_function (const char *name)
+{
+  enum built_in_function builtin_id;
+  if (!find_builtin_by_name (name, builtin_id))
+{
+  m_ctxt-add_error (NULL, builtin \%s\ not found, name);
+  return NULL;
+}
+
+  gcc_assert (builtin_id = 

[PATCH 08/27] New file: gcc/jit/libgccjit.h

2014-10-31 Thread David Malcolm
This header is the public API for the library.

gcc/jit/
* libgccjit.h: New.
---
 gcc/jit/libgccjit.h | 977 
 1 file changed, 977 insertions(+)
 create mode 100644 gcc/jit/libgccjit.h

diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h
new file mode 100644
index 000..8e03412
--- /dev/null
+++ b/gcc/jit/libgccjit.h
@@ -0,0 +1,977 @@
+/* A pure C API to enable client code to embed GCC as a JIT-compiler.
+   Copyright (C) 2013-2014 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+http://www.gnu.org/licenses/.  */
+
+#ifndef LIBGCCJIT_H
+#define LIBGCCJIT_H
+
+#ifdef __cplusplus
+extern C {
+#endif /* __cplusplus */
+
+/**
+ Data structures.
+ **/
+/* All structs within the API are opaque. */
+
+/* A gcc_jit_context encapsulates the state of a compilation.  It goes
+   through two states:
+
+   (1) initial, during which you can set up options on it, and add
+   types, functions and code, using the API below.
+   Invoking gcc_jit_context_compile on it transitions it to the
+   after compilation state.
+
+   (2) after compilation, when you can call gcc_jit_context_release to
+   clean up.  */
+typedef struct gcc_jit_context gcc_jit_context;
+
+/* A gcc_jit_result encapsulates the result of a compilation.  */
+typedef struct gcc_jit_result gcc_jit_result;
+
+/* An object created within a context.  Such objects are automatically
+   cleaned up when the context is released.
+
+   The class hierarchy looks like this:
+
+ +- gcc_jit_object
+ +- gcc_jit_location
+ +- gcc_jit_type
+   +- gcc_jit_struct
+ +- gcc_jit_field
+ +- gcc_jit_function
+ +- gcc_jit_block
+ +- gcc_jit_rvalue
+ +- gcc_jit_lvalue
+ +- gcc_jit_param
+*/
+typedef struct gcc_jit_object gcc_jit_object;
+
+/* A gcc_jit_location encapsulates a source code location, so that
+   you can (optionally) associate locations in your language with
+   statements in the JIT-compiled code, allowing the debugger to
+   single-step through your language.
+
+   Note that to do so, you also need to enable
+ GCC_JIT_BOOL_OPTION_DEBUGINFO
+   on the gcc_jit_context.
+
+   gcc_jit_location instances are optional; you can always pass
+   NULL.  */
+typedef struct gcc_jit_location gcc_jit_location;
+
+/* A gcc_jit_type encapsulates a type e.g. int or a struct foo*.  */
+typedef struct gcc_jit_type gcc_jit_type;
+
+/* A gcc_jit_field encapsulates a field within a struct; it is used
+   when creating a struct type (using gcc_jit_context_new_struct_type).
+   Fields cannot be shared between structs.  */
+typedef struct gcc_jit_field gcc_jit_field;
+
+/* A gcc_jit_struct encapsulates a struct type, either one that we have
+   the layout for, or an opaque type.  */
+typedef struct gcc_jit_struct gcc_jit_struct;
+
+/* A gcc_jit_function encapsulates a function: either one that you're
+   creating yourself, or a reference to one that you're dynamically
+   linking to within the rest of the process.  */
+typedef struct gcc_jit_function gcc_jit_function;
+
+/* A gcc_jit_block encapsulates a basic block of statements within a
+   function (i.e. with one entry point and one exit point).
+
+   Every block within a function must be terminated with a conditional,
+   a branch, or a return.
+
+   The blocks within a function form a directed graph.
+
+   The entrypoint to the function is the first block created within
+   it.
+
+   All of the blocks in a function must be reachable via some path from
+   the first block.
+
+   It's OK to have more than one return from a function (i.e. multiple
+   blocks that terminate by returning).  */
+typedef struct gcc_jit_block gcc_jit_block;
+
+/* A gcc_jit_rvalue is an expression within your code, with some type.  */
+typedef struct gcc_jit_rvalue gcc_jit_rvalue;
+
+/* A gcc_jit_lvalue is a storage location within your code (e.g. a
+   variable, a parameter, etc).  It is also a gcc_jit_rvalue; use
+   gcc_jit_lvalue_as_rvalue to cast.  */
+typedef struct gcc_jit_lvalue gcc_jit_lvalue;
+
+/* A gcc_jit_param is a function parameter, used when creating a
+   gcc_jit_function.  It is also a gcc_jit_lvalue (and thus also an
+   rvalue); use gcc_jit_param_as_lvalue to 

[PATCH 24/27] Documentation: add topics subdirectory

2014-10-31 Thread David Malcolm
This patch adds a series of topic-based reference articles, intended
to give developers who've read the tutorial more detailed descriptions
of particular aspects of the library.

gcc/jit/
* docs/topics/contexts.rst: New.
* docs/topics/expressions.rst: New.
* docs/topics/functions.rst: New.
* docs/topics/index.rst: New.
* docs/topics/locations.rst: New.
* docs/topics/objects.rst: New.
* docs/topics/results.rst: New.
* docs/topics/types.rst: New.
---
 gcc/jit/docs/topics/contexts.rst| 315 ++
 gcc/jit/docs/topics/expressions.rst | 524 
 gcc/jit/docs/topics/functions.rst   | 311 +
 gcc/jit/docs/topics/index.rst   |  30 +++
 gcc/jit/docs/topics/locations.rst   |  69 +
 gcc/jit/docs/topics/objects.rst |  86 ++
 gcc/jit/docs/topics/results.rst |  48 
 gcc/jit/docs/topics/types.rst   | 217 +++
 8 files changed, 1600 insertions(+)
 create mode 100644 gcc/jit/docs/topics/contexts.rst
 create mode 100644 gcc/jit/docs/topics/expressions.rst
 create mode 100644 gcc/jit/docs/topics/functions.rst
 create mode 100644 gcc/jit/docs/topics/index.rst
 create mode 100644 gcc/jit/docs/topics/locations.rst
 create mode 100644 gcc/jit/docs/topics/objects.rst
 create mode 100644 gcc/jit/docs/topics/results.rst
 create mode 100644 gcc/jit/docs/topics/types.rst

diff --git a/gcc/jit/docs/topics/contexts.rst b/gcc/jit/docs/topics/contexts.rst
new file mode 100644
index 000..d8dd4f8
--- /dev/null
+++ b/gcc/jit/docs/topics/contexts.rst
@@ -0,0 +1,315 @@
+.. Copyright (C) 2014 Free Software Foundation, Inc.
+   Originally contributed by David Malcolm dmalc...@redhat.com
+
+   This is free software: you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see
+   http://www.gnu.org/licenses/.
+
+.. default-domain:: c
+
+Compilation contexts
+
+
+.. type:: gcc_jit_context
+
+The top-level of the API is the :c:type:`gcc_jit_context` type.
+
+A :c:type:`gcc_jit_context` instance encapsulates the state of a
+compilation.
+
+You can set up options on it, and add types, functions and code.
+Invoking :c:func:`gcc_jit_context_compile` on it gives you a
+:c:type:`gcc_jit_result`.
+
+Lifetime-management
+---
+Contexts are the unit of lifetime-management within the API: objects
+have their lifetime bounded by the context they are created within, and
+cleanup of such objects is done for you when the context is released.
+
+.. function:: gcc_jit_context *gcc_jit_context_acquire (void)
+
+  This function acquires a new :c:type:`gcc_jit_object *` instance,
+  which is independent of any others that may be present within this
+  process.
+
+.. function:: void gcc_jit_context_release (gcc_jit_context *ctxt)
+
+  This function releases all resources associated with the given context.
+  Both the context itself and all of its :c:type:`gcc_jit_object *`
+  instances are cleaned up.  It should be called exactly once on a given
+  context.
+
+  It is invalid to use the context or any of its contextual objects
+  after calling this.
+
+  .. code-block:: c
+
+gcc_jit_context_release (ctxt);
+
+.. function:: gcc_jit_context * gcc_jit_context_new_child_context 
(gcc_jit_context *parent_ctxt)
+
+   Given an existing JIT context, create a child context.
+
+   The child inherits a copy of all option-settings from the parent.
+
+   The child can reference objects created within the parent, but not
+   vice-versa.
+
+   The lifetime of the child context must be bounded by that of the
+   parent: you should release a child context before releasing the parent
+   context.
+
+   If you use a function from a parent context within a child context,
+   you have to compile the parent context before you can compile the
+   child context, and the gcc_jit_result of the parent context must
+   outlive the gcc_jit_result of the child context.
+
+   This allows caching of shared initializations.  For example, you could
+   create types and declarations of global functions in a parent context
+   once within a process, and then create child contexts whenever a
+   function or loop becomes hot. Each such child context can be used for
+   JIT-compiling just one function or loop, but can reference types
+   and helper functions created within the parent context.
+
+   Contexts can be arbitrarily nested, provided the above rules are
+   

[PATCH 17/27] New file: gcc/jit/libgccjit++.h

2014-10-31 Thread David Malcolm
This adds a C++ wrapper API, with syntactic sugar for reducing the
verbosity compared to the C API.

gcc/jit/
* libgccjit++.h: New.
---
 gcc/jit/libgccjit++.h | 1574 +
 1 file changed, 1574 insertions(+)
 create mode 100644 gcc/jit/libgccjit++.h

diff --git a/gcc/jit/libgccjit++.h b/gcc/jit/libgccjit++.h
new file mode 100644
index 000..67ed5d5
--- /dev/null
+++ b/gcc/jit/libgccjit++.h
@@ -0,0 +1,1574 @@
+/* A C++ API for libgccjit, purely as inline wrapper functions.
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+http://www.gnu.org/licenses/.  */
+
+#ifndef LIBGCCJIT_PLUS_PLUS_H
+#define LIBGCCJIT_PLUS_PLUS_H
+
+#include libgccjit.h
+
+#include limits
+#include ostream
+#include vector
+
+/
+ C++ API
+ /
+
+namespace gccjit
+{
+  class context;
+  class location;
+  class field;
+  class type;
+  class struct_;
+  class param;
+  class function;
+  class block;
+  class rvalue;
+  class lvalue;
+
+  /* Errors within the API become C++ exceptions of this class.  */
+  class error
+  {
+  };
+
+  class object
+  {
+  public:
+context get_context () const;
+
+std::string get_debug_string () const;
+
+  protected:
+object ();
+object (gcc_jit_object *obj);
+
+gcc_jit_object *get_inner_object () const;
+
+  private:
+gcc_jit_object *m_inner_obj;
+  };
+
+  inline std::ostream operator  (std::ostream stream, const object obj);
+
+  /* Some client code will want to supply source code locations, others
+ won't.  To avoid doubling the number of entrypoints, everything
+ accepting a location also has a default argument.  To do this, the
+ other classes need to see that location has a default constructor,
+ hence we need to declare it first.  */
+  class location : public object
+  {
+  public:
+location ();
+location (gcc_jit_location *loc);
+
+gcc_jit_location *get_inner_location () const;
+  };
+
+  class context
+  {
+  public:
+static context acquire ();
+context ();
+context (gcc_jit_context *ctxt);
+
+gccjit::context new_child_context ();
+
+gcc_jit_context *get_inner_context () { return m_inner_ctxt; }
+
+void release ();
+
+gcc_jit_result *compile ();
+
+void dump_to_file (const std::string path,
+  bool update_locations);
+
+void set_int_option (enum gcc_jit_int_option opt,
+int value);
+
+void set_bool_option (enum gcc_jit_bool_option opt,
+ int value);
+
+location
+new_location (const std::string filename,
+ int line,
+ int column);
+
+type get_type (enum gcc_jit_types kind);
+type get_int_type (size_t num_bytes, int is_signed);
+
+/* A way to map a specific int type, using the compiler to
+   get the details automatically e.g.:
+ gccjit::type type = get_int_type my_int_type_t ();  */
+template typename T
+type get_int_type ();
+
+type new_array_type (type element_type, int num_elements,
+location loc = location ());
+
+field new_field (type type_, const std::string name,
+location loc = location ());
+
+struct_ new_struct_type (const std::string name,
+std::vectorfield fields,
+location loc = location ());
+
+struct_ new_opaque_struct_type (const std::string name,
+   location loc = location ());
+
+param new_param (type type_,
+const std::string name,
+location loc = location ());
+
+function new_function (enum gcc_jit_function_kind kind,
+  type return_type,
+  const std::string name,
+  std::vectorparam params,
+  int is_variadic,
+  location loc = location ());
+
+function get_builtin_function (const std::string name);
+
+lvalue new_global (type type_,
+  const std::string name,
+  location loc = location ());
+
+rvalue new_rvalue (type numeric_type,
+  int value) const;
+rvalue 

[PATCH 16/27] New file: gcc/jit/jit-playback.c

2014-10-31 Thread David Malcolm
This files implements the gcc::jit::playback internal API, called by
the dummy frontend to replay the public API calls made to the
library.  A thin wrapper around trees.

gcc/jit/
* jit-playback.c: New.
---
 gcc/jit/jit-playback.c | 2104 
 1 file changed, 2104 insertions(+)
 create mode 100644 gcc/jit/jit-playback.c

diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
new file mode 100644
index 000..dc1b468
--- /dev/null
+++ b/gcc/jit/jit-playback.c
@@ -0,0 +1,2104 @@
+/* Internals of libgccjit: classes for playing back recorded API calls.
+   Copyright (C) 2013-2014 Free Software Foundation, Inc.
+   Contributed by David Malcolm dmalc...@redhat.com.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+http://www.gnu.org/licenses/.  */
+
+#include config.h
+#include system.h
+#include coretypes.h
+#include opts.h
+#include tree.h
+#include cgraph.h
+#include toplev.h
+#include timevar.h
+#include tree-cfg.h
+#include target.h
+#include convert.h
+#include stringpool.h
+#include stor-layout.h
+#include print-tree.h
+#include gimplify.h
+#include gcc-driver-name.h
+
+#include jit-common.h
+#include jit-playback.h
+
+
+/* gcc::jit::playback::context::build_cast uses the convert.h API,
+   which in turn requires the frontend to provide a convert
+   function, apparently as a fallback.
+
+   Hence we provide this dummy one, with the requirement that any casts
+   are handled before reaching this.  */
+extern tree convert (tree type, tree expr);
+
+tree
+convert (tree dst_type, tree expr)
+{
+  gcc_assert (gcc::jit::active_playback_ctxt);
+  gcc::jit::active_playback_ctxt-add_error (NULL, unhandled conversion);
+  fprintf (stderr, input expression:\n);
+  debug_tree (expr);
+  fprintf (stderr, requested type:\n);
+  debug_tree (dst_type);
+  return error_mark_node;
+}
+
+namespace gcc {
+namespace jit {
+
+/**
+ Playback.
+ **/
+
+/* The constructor for gcc::jit::playback::context.  */
+
+playback::context::context (recording::context *ctxt)
+  : m_recording_ctxt (ctxt),
+m_char_array_type_node (NULL),
+m_const_char_ptr (NULL)
+{
+  m_functions.create (0);
+  m_source_files.create (0);
+  m_cached_locations.create (0);
+}
+
+/* The destructor for gcc::jit::playback::context.  */
+
+playback::context::~context ()
+{
+  if (get_bool_option (GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES))
+fprintf (stderr, intermediate files written to %s\n, m_path_tempdir);
+  else
+{
+  /* Clean up .s/.so and tempdir. */
+  if (m_path_s_file)
+unlink (m_path_s_file);
+  if (m_path_so_file)
+unlink (m_path_so_file);
+  if (m_path_tempdir)
+rmdir (m_path_tempdir);
+}
+
+  free (m_path_template);
+  /* m_path_tempdir aliases m_path_template, or is NULL, so don't
+ attempt to free it .  */
+  free (m_path_c_file);
+  free (m_path_s_file);
+  free (m_path_so_file);
+  m_functions.release ();
+}
+
+/* A playback::context can reference GC-managed pointers.  Mark them
+   (by hand, rather than by gengtype).
+
+   This is called on the active playback context (if any) by the
+   my_ggc_walker hook in the jit_root_table in dummy-frontend.c.  */
+
+void
+playback::context::
+gt_ggc_mx ()
+{
+  int i;
+  function *func;
+  FOR_EACH_VEC_ELT (m_functions, i, func)
+{
+  if (ggc_test_and_set_mark (func))
+   func-gt_ggc_mx ();
+}
+}
+
+/* Given an enum gcc_jit_types value, get a tree type.  */
+
+static tree
+get_tree_node_for_type (enum gcc_jit_types type_)
+{
+  switch (type_)
+{
+case GCC_JIT_TYPE_VOID:
+  return void_type_node;
+
+case GCC_JIT_TYPE_VOID_PTR:
+  return ptr_type_node;
+
+case GCC_JIT_TYPE_BOOL:
+  return boolean_type_node;
+
+case GCC_JIT_TYPE_CHAR:
+  return char_type_node;
+case GCC_JIT_TYPE_SIGNED_CHAR:
+  return signed_char_type_node;
+case GCC_JIT_TYPE_UNSIGNED_CHAR:
+  return unsigned_char_type_node;
+
+case GCC_JIT_TYPE_SHORT:
+  return short_integer_type_node;
+case GCC_JIT_TYPE_UNSIGNED_SHORT:
+  return short_unsigned_type_node;
+
+case GCC_JIT_TYPE_CONST_CHAR_PTR:
+  {
+   tree const_char = build_qualified_type (char_type_node,
+   TYPE_QUAL_CONST);
+   return 

  1   2   >