This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Add OPTION_MASK_ISA_X86_64 and support TARGET_BI_ARCH == 2


On Wed, Mar 28, 2012 at 2:17 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, Mar 28, 2012 at 2:10 PM, Uros Bizjak <ubizjak@gmail.com> wrote:
>> On Wed, Mar 28, 2012 at 10:13 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Wed, Mar 28, 2012 at 12:51 PM, Uros Bizjak <ubizjak@gmail.com> wrote:
>>>> On Wed, Mar 28, 2012 at 9:33 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>
>>>>> What do we do with TARGET_64BIT and TARGET_64BIT_DEFAULT? ?They
>>>>> are used to indicate 64bit ISA like:
>>>>>
>>>>> collect2.c:/* TARGET_64BIT may be defined to use driver specific
>>>>> functionality. */
>>>>> collect2.c:#undef TARGET_64BIT
>>>>> collect2.c:#define TARGET_64BIT TARGET_64BIT_DEFAULT
>>>>> reg-stack.c: ?if ((flag_pic && !TARGET_64BIT)
>>>>> tlink.c:/* TARGET_64BIT may be defined to use driver specific functionality. */
>>>>> tlink.c:#undef TARGET_64BIT
>>>>> tlink.c:#define TARGET_64BIT TARGET_64BIT_DEFAULT
>>>>> xcoffout.c: ? ? ? if (lno > 0 && (TARGET_64BIT || lno <= (int)USHRT_MAX)) ? ? ? ? ?\
>>>>> config/darwin.c: ? ? ? ? ? ? ? && TARGET_64BIT
>>>>> config/darwin.c: ? ? ? ? ? && TARGET_64BIT
>>>>> config/darwin.c: ? ? ? ? ? ? ? ?: (TARGET_64BIT ? 2
>>>>> config/darwin.c: ? ? ?if (TARGET_64BIT && global_options.x_flag_objc_abi < 2)
>>>>> config/darwin.c: ? ? ?if (!TARGET_64BIT && global_options.x_flag_objc_abi >= 2)
>>>>> config/darwin.c: ? ? ?&& !TARGET_64BIT)
>>>>> config/darwin.c: ?if (!TARGET_64BIT) ? ? ? ? ? ? ? ? ? ? ? ? ? ?\
>>>>> config/darwin.c: ?if (!TARGET_64BIT ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
>>>>> config/darwin.h: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?flag_next_runtime && !TARGET_64BIT; ? ? \
>>>>> config/sol2-bi.h:#define WCHAR_TYPE (TARGET_64BIT ? "int" : "long int")
>>>>> config/sol2-bi.h:#define WINT_TYPE (TARGET_64BIT ? "int" : "long int")
>>>>>
>>>>> Should we keep them? Right now I have
>>>>>
>>>>> #define TARGET_64BIT ? ?OPTION_ARCH_X86_64
>>>>>
>>>>> and
>>>>>
>>>>> #define TARGET_64BIT_DEFAULT (OPTION_MASK_ARCH_X86_64 | OPTION_MASK_ISA_64)
>>>>>
>>>>> Should we go with
>>>>>
>>>>> OPTION_MASK_ISA_64BIT -> stays the same
>>>>> OPTION_MASK_ISA_X86_64 -> OPTION_MASK_ABI_64
>>>>> OPTION_MASK_ISA_X32 -> ?OPTION_MASK_ABI_X32
>>>>
>>>> Yes, the above is IMO much better. We have to separate ABI and ISA
>>>> defines in some meaningful way.
>>>>
>>>> Uros.
>>>
>>> Here is the new patch. ?OK for trunk if there are no regressions on
>>> Linux/ia32 and Linux/x86-64?
>>
>> @@ -2657,7 +2657,7 @@ ix86_target_string (HOST_WIDE_INT isa, int
>> flags, const char *arch,
>> ? ? ?preceding options while match those first. ?*/
>> ? static struct ix86_target_opts isa_opts[] =
>> ? {
>> - ? ?{ "-m64", ? ? ? ? ?OPTION_MASK_ISA_64BIT },
>> + ? ?{ "-m64", ? ? ? ? ?OPTION_MASK_ABI_64 },
>> ? ? { "-mfma4", ? ? ? ? ? ? ? ?OPTION_MASK_ISA_FMA4 },
>>
>> Please add -mx32 here. Probably also -m32.
>
> I will add -mx32. ?Adding -m32 is hard since clearing the
> OPTION_MASK_ISA_64BIT bit isn't supported here. ?Can I
> try
>
> { "!-m32", ? ? ? ? ?OPTION_MASK_ISA_64BIT },

It turns out I can just remove -m64 and handle -m32/-m64/-mx32
together.

>> ?#define TARGET_64BIT ? OPTION_ISA_64BIT
>> -#define TARGET_X32 ? ? OPTION_ISA_X32
>> +#define TARGET_X32 ? ? OPTION_ABI_X32
>> ?#define TARGET_MMX ? ? OPTION_ISA_MMX
>> ?#define TARGET_3DNOW ? OPTION_ISA_3DNOW
>> ?#define TARGET_3DNOW_A OPTION_ISA_3DNOW_A
>> @@ -77,7 +77,7 @@ see the files COPYING3 and COPYING.RUNTIME
>> respectively. ?If not, see
>> ?#define TARGET_F16C ? ?OPTION_ISA_F16C
>> ?#define TARGET_RTM ? ? ?OPTION_ISA_RTM
>>
>> -#define TARGET_LP64 ? ?(TARGET_64BIT && !TARGET_X32)
>> +#define TARGET_LP64 ? ?OPTION_ABI_64
>>
>> Please group new OPTION_ABI_xxx defines together, after ISA defines.
>
> Will do.
>
>> The patch is OK, but please also get approval from Joseph (options maintainer).
>>
>

Here is the updated patch.  I will wait for OK from Joseph.

Thanks,

-- 
H.J.
2012-03-28  H.J. Lu  <hongjiu.lu@intel.com>

	* config/i386/biarch64.h (TARGET_64BIT_DEFAULT): Add
	OPTION_MASK_ABI_64.

	* config/i386/gnu-user64.h (SPEC_64): Support TARGET_BI_ARCH == 2.
	(SPEC_X32): Likewise.
	(MULTILIB_DEFAULTS): Likewise.

	* config/i386/i386.c (isa_opts): Remove -m64.
	(ix86_target_string): Properly handle -m32/-m64/-mx32.
	(ix86_option_override_internal): Properly
	set OPTION_MASK_ISA_64BIT and OPTION_MASK_ISA_X32 as well as
	handle -m32, -m64 and -mx32.

	* config/i386/i386.h (TARGET_X32): Replace OPTION_ISA_X32
	with OPTION_ABI_X32.  Moved after TARGET_LP64.
	(TARGET_LP64): Changed to OPTION_ABI_64.

	* config/i386/i386.opt (m64): Replace ISA_64BIT with ABI_64.
	(mx32): Replace ISA_X32 with ABI_X32.

diff --git a/gcc/config/i386/biarch64.h b/gcc/config/i386/biarch64.h
index 629ec98..0c3811e 100644
--- a/gcc/config/i386/biarch64.h
+++ b/gcc/config/i386/biarch64.h
@@ -25,5 +25,5 @@ a copy of the GCC Runtime Library Exception along with this program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
-#define TARGET_64BIT_DEFAULT OPTION_MASK_ISA_64BIT
+#define TARGET_64BIT_DEFAULT (OPTION_MASK_ISA_64BIT | OPTION_MASK_ABI_64)
 #define TARGET_BI_ARCH 1
diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
index 954f3b2..6f7b5de 100644
--- a/gcc/config/i386/gnu-user64.h
+++ b/gcc/config/i386/gnu-user64.h
@@ -58,8 +58,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #if TARGET_64BIT_DEFAULT
 #define SPEC_32 "m32"
+#if TARGET_BI_ARCH == 2
+#define SPEC_64 "m64"
+#define SPEC_X32 "m32|m64:;"
+#else
 #define SPEC_64 "m32|mx32:;"
 #define SPEC_X32 "mx32"
+#endif
 #else
 #define SPEC_32 "m64|mx32:;"
 #define SPEC_64 "m64"
@@ -95,7 +100,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    %{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s"
 
 #if TARGET_64BIT_DEFAULT
+#if TARGET_BI_ARCH == 2
+#define MULTILIB_DEFAULTS { "mx32" }
+#else
 #define MULTILIB_DEFAULTS { "m64" }
+#endif
 #else
 #define MULTILIB_DEFAULTS { "m32" }
 #endif
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 18172a1..cd3ade7 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -2657,7 +2657,6 @@ ix86_target_string (HOST_WIDE_INT isa, int flags, const char *arch,
      preceding options while match those first.  */
   static struct ix86_target_opts isa_opts[] =
   {
-    { "-m64",		OPTION_MASK_ISA_64BIT },
     { "-mfma4",		OPTION_MASK_ISA_FMA4 },
     { "-mfma",		OPTION_MASK_ISA_FMA },
     { "-mxop",		OPTION_MASK_ISA_XOP },
@@ -2730,6 +2729,7 @@ ix86_target_string (HOST_WIDE_INT isa, int flags, const char *arch,
   size_t len;
   size_t line_len;
   size_t sep_len;
+  const char *abi;
 
   memset (opts, '\0', sizeof (opts));
 
@@ -2747,6 +2747,21 @@ ix86_target_string (HOST_WIDE_INT isa, int flags, const char *arch,
       opts[num++][1] = tune;
     }
 
+  /* Add -m32/-m64/-mx32.  */
+  if ((isa & OPTION_MASK_ISA_64BIT) != 0)
+    {
+      if ((isa & OPTION_MASK_ABI_64) != 0)
+	abi = "-m64";
+      else
+	abi = "-mx32";
+      isa &= ~ (OPTION_MASK_ISA_64BIT
+		| OPTION_MASK_ABI_64
+		| OPTION_MASK_ABI_X32);
+    }
+  else
+    abi = "-m32";
+  opts[num++][0] = abi;
+
   /* Pick out the options in isa options.  */
   for (i = 0; i < ARRAY_SIZE (isa_opts); i++)
     {
@@ -3102,8 +3117,45 @@ ix86_option_override_internal (bool main_args_p)
   SUBSUBTARGET_OVERRIDE_OPTIONS;
 #endif
 
+  /* Turn off both OPTION_MASK_ABI_64 and OPTION_MASK_ABI_X32 if
+     TARGET_64BIT is false.  */
+  if (!TARGET_64BIT)
+    ix86_isa_flags &= ~(OPTION_MASK_ABI_64 | OPTION_MASK_ABI_X32);
+#ifdef TARGET_BI_ARCH
+  else
+    {
+#if TARGET_BI_ARCH == 1
+      /* When TARGET_BI_ARCH == 1, by default, OPTION_MASK_ABI_64
+	 is on and OPTION_MASK_ABI_X32 is off.  We turn off
+	 OPTION_MASK_ABI_64 if OPTION_MASK_ABI_X32 is turned on by
+	 -mx32.  */
+      if (TARGET_X32)
+	ix86_isa_flags &= ~OPTION_MASK_ABI_64;
+#else
+      /* When TARGET_BI_ARCH == 2, by default, OPTION_MASK_ABI_X32 is
+	 on and OPTION_MASK_ABI_64 is off.  We turn off
+	 OPTION_MASK_ABI_X32 if OPTION_MASK_ABI_64 is turned on by
+	 -m64.  */
+      if (TARGET_LP64)
+	ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
+#endif
+    }
+#endif
+
   if (TARGET_X32)
-    ix86_isa_flags |= OPTION_MASK_ISA_64BIT;
+    {
+      /* Always turn on OPTION_MASK_ISA_64BIT and turn off
+	 OPTION_MASK_ABI_64 for TARGET_X32.  */
+      ix86_isa_flags |= OPTION_MASK_ISA_64BIT;
+      ix86_isa_flags &= ~OPTION_MASK_ABI_64;
+    }
+  else if (TARGET_LP64)
+    {
+      /* Always turn on OPTION_MASK_ISA_64BIT and turn off
+	 OPTION_MASK_ABI_X32 for TARGET_LP64.  */
+      ix86_isa_flags |= OPTION_MASK_ISA_64BIT;
+      ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
+    }
 
   /* -fPIC is the default for x86_64.  */
   if (TARGET_MACHO && TARGET_64BIT)
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index a53c70a..7ba90c7 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -42,7 +42,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 /* Redefines for option macros.  */
 
 #define TARGET_64BIT	OPTION_ISA_64BIT
-#define TARGET_X32	OPTION_ISA_X32
 #define TARGET_MMX	OPTION_ISA_MMX
 #define TARGET_3DNOW	OPTION_ISA_3DNOW
 #define TARGET_3DNOW_A	OPTION_ISA_3DNOW_A
@@ -77,7 +76,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define TARGET_F16C	OPTION_ISA_F16C
 #define TARGET_RTM      OPTION_ISA_RTM
 
-#define TARGET_LP64	(TARGET_64BIT && !TARGET_X32)
+#define TARGET_LP64	OPTION_ABI_64
+#define TARGET_X32	OPTION_ABI_X32
 
 /* SSE4.1 defines round instructions */
 #define	OPTION_MASK_ISA_ROUND	OPTION_MASK_ISA_SSE4_1
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 29f1082..91a69fb 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -425,11 +425,11 @@ Target RejectNegative Negative(m64) Report InverseMask(ISA_64BIT) Var(ix86_isa_f
 Generate 32bit i386 code
 
 m64
-Target RejectNegative Negative(mx32) Report Mask(ISA_64BIT) Var(ix86_isa_flags) Save
+Target RejectNegative Negative(mx32) Report Mask(ABI_64) Var(ix86_isa_flags) Save
 Generate 64bit x86-64 code
 
 mx32
-Target RejectNegative Negative(m32) Report Mask(ISA_X32) Var(ix86_isa_flags) Save
+Target RejectNegative Negative(m32) Report Mask(ABI_X32) Var(ix86_isa_flags) Save
 Generate 32bit x86-64 code
 
 mmmx

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]