From patchwork Thu Aug 19 22:54:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1518863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=Fp3P5m1D; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GrKpy6Z7lz9sVw for ; Fri, 20 Aug 2021 08:55:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F67F39B3C17 for ; Thu, 19 Aug 2021 22:55:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 5FE3A3857C59 for ; Thu, 19 Aug 2021 22:54:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5FE3A3857C59 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=tljbaleU4nfBSB5tv2z6MzRA7ey8SURLO2wQDyS2wPI=; b=Fp3P5m1DorDWM5mnoLPEF4C4oI Ld37dfkZte5Lkjv6HE3yg27aMeIG8Q9oBBUPYRiYO5G66K8jXctaJ98liF6s0PmWAwg6wCwm158XI 3s2cjf8e0cxYAsKbOf9zQcQpnNcjMIPVA4DgpE1iUeV5nrm5Bsx7i8Ld0Ur27ekypGb2Ew+CMwaU9 h3B6/q2w6IRhtJ3CM4yuMHcIbtew7Jv6aMWwJKuPXLMEtlh0gOaLGMnNNII5DSOLAoJo3msRM1yvW Z8oaKUjbxkw83HvmXw1fIssKoeZsPXEcwMuXIKKj0t4mp8G8tLIws2ln+Ev44kLiUjcZEi1t2Khq6 iAbPk6kQ==; Received: from host109-154-46-127.range109-154.btcentralplus.com ([109.154.46.127]:62230 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mGqvp-0002eD-QP; Thu, 19 Aug 2021 18:54:42 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] nvptx: Add a __PTX_ISA__ predefined macro based on target ISA. Date: Thu, 19 Aug 2021 23:54:39 +0100 Message-ID: <001b01d7954d$32192c90$964b85b0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdeVTGo6kszZiRl7Som4G/ZpbFbr+w== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch adds a __PTX_ISA__ predefined macro to the nvptx backend that allows code to check the compute model being targeted by the compiler. This is equivalent to the __CUDA_ARCH__ macro defined by CUDA's nvcc compiler, but to avoid causing problems for source code that checks for that compiler, this macro uses GCC's nomenclature; it's easy enough for users to "#define __CUDA_ARCH__ __PTX_ISA__", but I'm also happy to modify this patch to define __CUDA_ARCH__ if that's the preference of the nvptx backend maintainers. What might have been a four line patch is actually a little more complicated, as this patch takes the opportunity to upgrade the nvptx backend to use the now preferred nvptx-c.c idiom. This patch has been tested with a cross-compiler from x86_64-pc-linux-gnu to nvptx-none, and tested with "make -k check" with no new failures. This feature is useful for implementing clock() on nvptx in newlib. Ok for mainline? 2021-08-19 Roger Sayle gcc/ChangeLog * config.gcc (nvptx-*-*): Define {c,c++}_target_objs. * config/nvptx/nvptx-protos.h (nvptx_cpu_cpp_builtins): Prototype. * config/nvptx/nvptx.h (TARGET_CPU_CPP_BUILTINS): Implement with a call to the new nvptx_cpu_cpp_builtins function in nvptx-c.c. * config/nvptx/t-nvptx (nvptx-c.o): New rule. * config/nvptx/nvptx-c.c: New source file. (nvptx_cpu_cpp_builtins): Move implementation here. Roger --- Roger Sayle NextMove Software Cambridge, UK diff --git a/gcc/config.gcc b/gcc/config.gcc index 93e2b32..cbad989 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -468,6 +468,8 @@ nios2-*-*) ;; nvptx-*-*) cpu_type=nvptx + c_target_objs="nvptx-c.o" + cxx_target_objs="nvptx-c.o" ;; or1k*-*-*) cpu_type=or1k diff --git a/gcc/config/nvptx/nvptx-protos.h b/gcc/config/nvptx/nvptx-protos.h index b7e6ae2..b29ddc9 100644 --- a/gcc/config/nvptx/nvptx-protos.h +++ b/gcc/config/nvptx/nvptx-protos.h @@ -40,6 +40,7 @@ extern void nvptx_output_aligned_decl (FILE *file, const char *name, extern void nvptx_function_end (FILE *); extern void nvptx_output_skip (FILE *, unsigned HOST_WIDE_INT); extern void nvptx_output_ascii (FILE *, const char *, unsigned HOST_WIDE_INT); +extern void nvptx_cpu_cpp_builtins (void); extern void nvptx_register_pragmas (void); extern unsigned int nvptx_data_alignment (const_tree, unsigned int); diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h index fdaacdd..d367174 100644 --- a/gcc/config/nvptx/nvptx.h +++ b/gcc/config/nvptx/nvptx.h @@ -34,17 +34,7 @@ nvptx-as. */ #define ASM_SPEC "%{misa=*:-m %*; :-m sm_35}" -#define TARGET_CPU_CPP_BUILTINS() \ - do \ - { \ - builtin_assert ("machine=nvptx"); \ - builtin_assert ("cpu=nvptx"); \ - builtin_define ("__nvptx__"); \ - if (TARGET_SOFT_STACK) \ - builtin_define ("__nvptx_softstack__"); \ - if (TARGET_UNIFORM_SIMT) \ - builtin_define ("__nvptx_unisimt__"); \ - } while (0) +#define TARGET_CPU_CPP_BUILTINS() nvptx_cpu_cpp_builtins () /* Avoid the default in ../../gcc.c, which adds "-pthread", which is not supported for nvptx. */ diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx index 6c1010d..d33bacd 100644 --- a/gcc/config/nvptx/t-nvptx +++ b/gcc/config/nvptx/t-nvptx @@ -1,3 +1,7 @@ +nvptx-c.o: $(srcdir)/config/nvptx/nvptx-c.c + $(COMPILE) $< + $(POSTCOMPILE) + CFLAGS-mkoffload.o += $(DRIVER_DEFINES) \ -DGCC_INSTALL_NAME=\"$(GCC_INSTALL_NAME)\" mkoffload.o: $(srcdir)/config/nvptx/mkoffload.c diff --git a/gcc/config/nvptx/nvptx-c.c b/gcc/config/nvptx/nvptx-c.c new file mode 100644 index 0000000..5a7a0ef --- /dev/null +++ b/gcc/config/nvptx/nvptx-c.c @@ -0,0 +1,47 @@ +/* Subroutines for the C front end on the NVPTX architecture. + * Copyright (C) 2021 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 + * . */ + +#define IN_TARGET_CODE 1 + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "target.h" +#include "c-family/c-common.h" +#include "memmodel.h" +#include "tm_p.h" +#include "c-family/c-pragma.h" + +/* Function to tell the preprocessor about the defines for the target. */ +void +nvptx_cpu_cpp_builtins (void) +{ + cpp_assert (parse_in, "machine=nvptx"); + cpp_assert (parse_in, "cpu=nvptx"); + cpp_define (parse_in, "__nvptx__"); + if (TARGET_SOFT_STACK) + cpp_define (parse_in, "__nvptx_softstack__"); + if (TARGET_UNIFORM_SIMT) + cpp_define (parse_in,"__nvptx_unisimt__"); + if (TARGET_SM35) + cpp_define (parse_in, "__PTX_ISA__=350"); + else + cpp_define (parse_in,"__PTX_ISA__=300"); +} +