From patchwork Thu Feb 19 08:39:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 441548 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C749A14008F for ; Thu, 19 Feb 2015 19:40:19 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; q=dns; s=default; b=pXXXlI0YQgv9z56T WAJxyb3qimM9VY1S+PC2s9vv8CHehAeL2vDyZ3c3zQCR9gUi2EVsPYjU+DBgYQ6x CYA0dkME9CzMchlSTghmZWK793N1RSVbRlVcDA4WxEk0AMy6y6arQ4zfOCeOaLoC ZrkkvsMK6QQu4DUjTQwS9B2N+2Y= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; s=default; bh=/CIdKGxFPoi/8UmeASYK3S G1pJs=; b=B0vFUEDj5Lsj0bFCwtNMjc6mQY3xnIQLr8yASM4nq1smsAJEMvo7fI W2OWGLUroIR0KN7I43cbfAxM1/SF3ltGo7td96gRzu0vjZlkHlGVQhiXYy46DXIt YfAVgO3EKPrgGDkT0fCODa4oAzvS/Pvy2H4/oULtbJwNO5g9k7IBM= Received: (qmail 30090 invoked by alias); 19 Feb 2015 08:40:11 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 30075 invoked by uid 89); 19 Feb 2015 08:40:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Feb 2015 08:40:09 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1YOMeR-0007eH-Vo from Thomas_Schwinge@mentor.com ; Thu, 19 Feb 2015 00:40:04 -0800 Received: from feldtkeller.schwinge.homeip.net (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Thu, 19 Feb 2015 08:40:02 +0000 From: Thomas Schwinge To: Bernd Schmidt CC: Ilya Verbin , Jakub Jelinek , , Richard Biener , Kirill Yukhin , Andrey Turetskiy Subject: Re: [PATCH 6/n] OpenMP 4.0 offloading infrastructure: option handling In-Reply-To: <87d257ducq.fsf@kepler.schwinge.homeip.net> References: <20141011144900.GA16368@msticlxl57.ims.intel.com> <20141013101909.GT10376@tucnak.redhat.com> <20141013103311.GA64058@msticlxl57.ims.intel.com> <87d257ducq.fsf@kepler.schwinge.homeip.net> User-Agent: Notmuch/0.9-101-g81dad07 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-pc-linux-gnu) Date: Thu, 19 Feb 2015 09:39:52 +0100 Message-ID: <87lhjue1lz.fsf@schwinge.name> MIME-Version: 1.0 Hi! On Wed, 18 Feb 2015 18:04:21 +0100, I wrote: > On Mon, 13 Oct 2014 14:33:11 +0400, Ilya Verbin wrote: > > On 13 Oct 12:19, Jakub Jelinek wrote: > > > On Sat, Oct 11, 2014 at 06:49:00PM +0400, Ilya Verbin wrote: > > > > 2. -foffload-abi=[lp64|ilp32] > > > > This option is supposed to tell mkoffload (and offload compiler) which ABI is > > > > used in streamed GIMPLE. This option is desirable, because host and offload > > > > compilers must have the same ABI. The option is generated by the host compiler > > > > automatically, it should not be specified by user. > > > > > > But I'd like to understand why is this one needed. > > > Why should the compilers care? Aggregates layout and alignment of > > > integral/floating types must match between host and offload compilers, sure, > > > but isn't that something streamed already in the LTO bytecode? > > > Or is LTO streamer not streaming some types like long_type_node? > > > I'd expect if host and offload compiler disagree on long type size that > > > you'd just use a different integral type with the same size as long on the > > > host. > > > Different sized pointers are of course a bigger problem, but can't you just > > > error out on that during reading of the LTO, or even handle it (just use > > > some integral type for when is the pointer stored in memory, and just > > > convert to pointer after reads from memory, and convert back before storing > > > to memory). Erroring out during LTO streaming in sounds just fine to me > > > though. > > > > Actually this option was developed by Bernd, so I think PTX team is going to use > > it somehow. In MIC's case we're planning just to check in mkoffload that host > > and target compiler's ABI are the same. Without this check we will crash in LTO > > streamer with ICE, so I'd like to issue an error message, rather than crashing. > > In gcc/config/i386/intelmic-mkoffload.c, this option is now parsed to > initialize the target_ilp32 variable, which will then be used > (target_ilp32 ? "-m32" : "-m64") when invoking different tools. > > In nvptx, we've been using the following approach: > > --- gcc/config/nvptx/nvptx.h > +++ gcc/config/nvptx/nvptx.h > @@ -54,24 +54,28 @@ > > /* Type Layout. */ > > +#define TARGET_64BIT \ > + (flag_offload_abi == OFFLOAD_ABI_UNSET ? TARGET_ABI64 \ > + : flag_offload_abi == OFFLOAD_ABI_LP64 ? true : false) > + > #define DEFAULT_SIGNED_CHAR 1 > > #define SHORT_TYPE_SIZE 16 > #define INT_TYPE_SIZE 32 > -#define LONG_TYPE_SIZE (TARGET_ABI64 ? 64 : 32) > +#define LONG_TYPE_SIZE (TARGET_64BIT ? 64 : 32) > #define LONG_LONG_TYPE_SIZE 64 > #define FLOAT_TYPE_SIZE 32 > #define DOUBLE_TYPE_SIZE 64 > #define LONG_DOUBLE_TYPE_SIZE 64 > > #undef SIZE_TYPE > -#define SIZE_TYPE (TARGET_ABI64 ? "long unsigned int" : "unsigned int") > +#define SIZE_TYPE (TARGET_64BIT ? "long unsigned int" : "unsigned int") > #undef PTRDIFF_TYPE > -#define PTRDIFF_TYPE (TARGET_ABI64 ? "long int" : "int") > +#define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int") > > -#define POINTER_SIZE (TARGET_ABI64 ? 64 : 32) > +#define POINTER_SIZE (TARGET_64BIT ? 64 : 32) > > -#define Pmode (TARGET_ABI64 ? DImode : SImode) > +#define Pmode (TARGET_64BIT ? DImode : SImode) > > /* Registers. Since ptx is a virtual target, we just define a few > hard registers for special purposes and leave pseudos unallocated. */ > > Should we settle on one of the two, that is, either pass -m[...] from > mkoffload, or handle flag_offload_abi in the respective backend? I think > I prefer the intelmic-mkoffload.c approach; this seems cleaner to me: > mkoffload "configures" the offloading compiler. (Also, the flag 32-bit > vs. 64-bit flag may in fact be needed for tools other than the offloading > compiler). Well, "for instance", when in -m32 mode, we also need to use it in gcc/config/nvptx/mkoffload.c:compile_native -- otherwise, later on, the linker will not be happy with the request to link a 64-bit object file with 32-bit object files... > Bernd, is there any specific reason for the approach you had > chosen? OK to do the following instead? (Coding style/code copied from gcc/config/i386/intelmic-mkoffload.c for consistency.) Grüße, Thomas --- gcc/config/nvptx/mkoffload.c +++ gcc/config/nvptx/mkoffload.c @@ -126,6 +126,9 @@ static id_map *var_ids, **vars_tail = &var_ids; static const char *ptx_name; static const char *ptx_cfile_name; +/* Shows if we should compile binaries for i386 instead of x86-64. */ +bool target_ilp32 = false; + /* Delete tempfiles. */ /* Unlink a temporary file unless requested otherwise. */ @@ -883,6 +886,7 @@ compile_native (const char *infile, const char *outfile, const char *compiler) struct obstack argv_obstack; obstack_init (&argv_obstack); obstack_ptr_grow (&argv_obstack, compiler); + obstack_ptr_grow (&argv_obstack, target_ilp32 ? "-m32" : "-m64"); obstack_ptr_grow (&argv_obstack, infile); obstack_ptr_grow (&argv_obstack, "-c"); obstack_ptr_grow (&argv_obstack, "-o"); @@ -960,10 +964,23 @@ main (int argc, char **argv) passed with @file. Expand them into argv before processing. */ expandargv (&argc, &argv); + /* Find out whether we should compile binaries for i386 or x86-64. */ + for (int i = argc - 1; i > 0; i--) + if (strncmp (argv[i], "-foffload-abi=", sizeof ("-foffload-abi=") - 1) == 0) + { + if (strstr (argv[i], "ilp32")) + target_ilp32 = true; + else if (!strstr (argv[i], "lp64")) + fatal_error (input_location, + "unrecognizable argument of option -foffload-abi"); + break; + } + struct obstack argv_obstack; obstack_init (&argv_obstack); obstack_ptr_grow (&argv_obstack, driver); obstack_ptr_grow (&argv_obstack, "-xlto"); + obstack_ptr_grow (&argv_obstack, target_ilp32 ? "-m32" : "-m64"); obstack_ptr_grow (&argv_obstack, "-S"); for (int ix = 1; ix != argc; ix++) diff --git gcc/config/nvptx/nvptx.h gcc/config/nvptx/nvptx.h index 15460b7..e74d16f 100644 --- gcc/config/nvptx/nvptx.h +++ gcc/config/nvptx/nvptx.h @@ -58,28 +58,24 @@ /* Type Layout. */ -#define TARGET_64BIT \ - (flag_offload_abi == OFFLOAD_ABI_UNSET ? TARGET_ABI64 \ - : flag_offload_abi == OFFLOAD_ABI_LP64 ? true : false) - #define DEFAULT_SIGNED_CHAR 1 #define SHORT_TYPE_SIZE 16 #define INT_TYPE_SIZE 32 -#define LONG_TYPE_SIZE (TARGET_64BIT ? 64 : 32) +#define LONG_TYPE_SIZE (TARGET_ABI64 ? 64 : 32) #define LONG_LONG_TYPE_SIZE 64 #define FLOAT_TYPE_SIZE 32 #define DOUBLE_TYPE_SIZE 64 #define LONG_DOUBLE_TYPE_SIZE 64 #undef SIZE_TYPE -#define SIZE_TYPE (TARGET_64BIT ? "long unsigned int" : "unsigned int") +#define SIZE_TYPE (TARGET_ABI64 ? "long unsigned int" : "unsigned int") #undef PTRDIFF_TYPE -#define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int") +#define PTRDIFF_TYPE (TARGET_ABI64 ? "long int" : "int") -#define POINTER_SIZE (TARGET_64BIT ? 64 : 32) +#define POINTER_SIZE (TARGET_ABI64 ? 64 : 32) -#define Pmode (TARGET_64BIT ? DImode : SImode) +#define Pmode (TARGET_ABI64 ? DImode : SImode) /* Registers. Since ptx is a virtual target, we just define a few hard registers for special purposes and leave pseudos unallocated. */