From patchwork Fri Aug 2 04:16:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hau Hsu X-Patchwork-Id: 1968111 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=EPhz44/n; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZsxR46qmz1yYq for ; Fri, 2 Aug 2024 14:17:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A31F3858D39 for ; Fri, 2 Aug 2024 04:17:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id 00BA83858D35 for ; Fri, 2 Aug 2024 04:17:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 00BA83858D35 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 00BA83858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722572225; cv=none; b=jQ5uUBBULZu8e8rO5rSjYMwMwtv0lDOnidsHvHIfKzZE/bJZYXPv9EL+/4TINCdJfIDa72pM6FHtduVkVQ9Pqv7YJWAg4DEiSmt5Zy2hOYaAgUVI1aynSRWqIYKJpf691OGyC38y2U21ohH/SH0WgbLJRXr7RwP9b3F+lxiVl/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722572225; c=relaxed/simple; bh=ZQOtPlMp7TC5AO656ckeUrE5nKLt1KdSgiQF7IlICZk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=T18OpInxT4Svq5K4RETnDMYkmkymQzKn4FFYRjOTVyVARyq4MOonYlm7fKbbeJY9C2uhKFUTfJ2LRltw3+56/Ku3txjxAfjQry/lYr7DmnfA2SD+kwDBCiV5pdKu/5FOq8Et5UFjoWugohvMgzSD9OIlvGJ1E17k0aLVmLrAh9c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-70b2421471aso4947273a12.0 for ; Thu, 01 Aug 2024 21:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1722572221; x=1723177021; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=DMUDROmGBEUtaW1P1o9jr6AdDqpE6Yh3j9kDmEQBtU0=; b=EPhz44/nHhA7x5h3pbprfgFiumx2IiumAKKLiI4YjSGmALfKdGGSSGOJbIUJCf1dkW YxoMnojj/LDoWZy3XXAzXmKvzlsLXzjIRAWKmSGJ9DUteZoVLe/fEVRo+UURNJzcxJZo lxW8no/SW1U2+rMC1RKNVAhJj3vsB7xLP58I6dRcVTkWQYTPlAJE459GrWVOaAUl/y4U gF1nlYsGzNecTRGXS4XkRJejs1PsNZuPlHzNklbDQpzL7QmmUR4YTflwbGeLX6SrRrz4 feuqIsdzbpOqGsRR2JP6s6qmpHiSEUj5uB491GBDt+EJX43onAFEUuyKcniSvewK3iSo Bc6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722572221; x=1723177021; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DMUDROmGBEUtaW1P1o9jr6AdDqpE6Yh3j9kDmEQBtU0=; b=Cyr514nfpbc2GWri/pY1xH2eYwnPUUQrrGUlWXYHYUjyIoB4Gz2naoohk50PtcZ5+p DEF3NCeWtpYJAdAB+Oke9gRDupLEOWd4GLfc+TLJ9wiDBqsvDdQsykxrjyF8A5cYvHwu 0w7aN6gv3/4MmFXY3ARAodwcqSqqpxhLL1b6yPrAbmvlfLr5ccVwFvnPe57P9czxj8/I pTkKpHB7UOsA51YwXAwTx8f20dQZypR/2cVC++r0Wn4RhGQwm6y5Qsmz9lU+z9YhQyrI MDFWe4Q1PMuiBLcX6GBN/5RtFYmf2exO+3mldiuN/5HjcEbgSlPOo2ROxzDFBNeyPQDX EPTQ== X-Gm-Message-State: AOJu0YyoBNA+Uvtv5GTecMIpwNJjfxzGZZUfT1Q26ci82ifx1Dl1147J BO9dQe2ofGdUVtRuZm5kFpdoCh+L0U1KBW+JL0jRs6QKXuI5N6LC2QeXo10jQYOZkV2NBrxPILK H7UTw5lWUwjeDnxsaLB6uleByyBtcTO9YVMLs4MveqRjdEw5wVaG/BWZS1IvsYfeZhnLNwnZ3a+ phFF4GXEqCuNTiu9/NMrQMPjk9D3SlH4RsKdDgj4g= X-Google-Smtp-Source: AGHT+IF1MHPrpc2tLq3dlrrIds9obPvLUPCWmsIBjSxx7fVf28oU0nKzOj1SHTa04Wm/Ai+h7k8wCA== X-Received: by 2002:a05:6a21:c8d:b0:1c4:bbb8:5050 with SMTP id adf61e73a8af0-1c699620fd9mr2703765637.37.1722572220937; Thu, 01 Aug 2024 21:17:00 -0700 (PDT) Received: from sw05.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cfdc4064e4sm4270897a91.9.2024.08.01.21.16.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 21:17:00 -0700 (PDT) From: Hau Hsu To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, hau.hsu@sifive.com Subject: [PATCH] RISC-V: Add --with-cmodel configure option Date: Fri, 2 Aug 2024 12:16:58 +0800 Message-Id: <20240802041658.3629522-1-hau.hsu@sifive.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 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 Sometimes we want to use default cmodel other than medlow. Add a GCC configure option for that. gcc/ChangeLog: * config.gcc (riscv*-*-*): Add support for --with-cmodel configure option. * config/riscv/riscv.h (TARGET_RISCV_DEFAULT_CMODEL): Define default cmodel. * configure: Regenerate. * configure.ac: Add --with-cmodel configure option. * doc/install.texi: Document --with-cmodel configure option. * doc/invoke.texi (-mcmodel): Mention --with-cmodel configure option. --- gcc/config.gcc | 19 +++++++++++++++++-- gcc/config/riscv/riscv.h | 2 ++ gcc/configure | 15 +++++++++++++-- gcc/configure.ac | 5 +++++ gcc/doc/install.texi | 4 ++++ gcc/doc/invoke.texi | 6 ++++-- 6 files changed, 45 insertions(+), 6 deletions(-) diff --git a/gcc/config.gcc b/gcc/config.gcc index a36dd1bcbc6..a4537d4b940 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -4723,7 +4723,7 @@ case "${target}" in ;; riscv*-*-*) - supported_defaults="abi arch tune riscv_attribute isa_spec tls" + supported_defaults="abi arch tune riscv_attribute isa_spec tls cmodel" case "${target}" in riscv-* | riscv32*) xlen=32 ;; @@ -4879,6 +4879,21 @@ case "${target}" in exit 1 esac fi + + # Handle --with-cmodel. + if test "x${with_cmodel}" != xdefault; then + # Make sure --with-cmodel is valid. If it was not specified, + # use medlow as the default value. + case "${with_cmodel}" in + medlow | medany | compact) + ;; + *) + echo "invalid option for --with-cmodel: '${with_cmodel}', available values are 'medlow' 'medany' 'compact'" 1>&2 + exit 1 + ;; + esac + tm_defines="${tm_defines} TARGET_RISCV_DEFAULT_CMODEL=${with_cmodel}" + fi ;; mips*-*-*) @@ -6071,7 +6086,7 @@ case ${target} in esac t= -all_defaults="abi cpu cpu_32 cpu_64 arch arch_32 arch_64 tune tune_32 tune_64 schedule float mode fpu nan fp_32 odd_spreg_32 divide llsc mips-plt synci tls lxc1-sxc1 madd4 isa_spec compact-branches msa" +all_defaults="abi cpu cpu_32 cpu_64 arch arch_32 arch_64 tune tune_32 tune_64 schedule float mode fpu nan fp_32 odd_spreg_32 divide llsc mips-plt synci tls lxc1-sxc1 madd4 isa_spec compact-branches msa cmodel" for option in $all_defaults do eval "val=\$with_"`echo $option | sed s/-/_/g` diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index 6f040011864..68173ebccb4 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -65,6 +65,7 @@ extern const char *riscv_arch_help (int argc, const char **argv); --with-tune is ignored if -mtune or -mcpu is specified. --with-isa-spec is ignored if -misa-spec is specified. --with-tls is ignored if -mtls-dialect is specified. + --with-cmodel is ignored if -mcmodel is specified. But using default -march/-mtune value if -mcpu don't have valid option. */ #define OPTION_DEFAULT_SPECS \ @@ -77,6 +78,7 @@ extern const char *riscv_arch_help (int argc, const char **argv); {"abi", "%{!mabi=*:-mabi=%(VALUE)}" }, \ {"isa_spec", "%{!misa-spec=*:-misa-spec=%(VALUE)}" }, \ {"tls", "%{!mtls-dialect=*:-mtls-dialect=%(VALUE)}"}, \ + {"cmodel", "%{!mcmodel=*:-mcmodel=%(VALUE)}" }, \ #ifdef IN_LIBGCC2 #undef TARGET_64BIT diff --git a/gcc/configure b/gcc/configure index 557ea5fa3ac..826caf8dc2c 100755 --- a/gcc/configure +++ b/gcc/configure @@ -1000,6 +1000,7 @@ with_changes_root_url enable_languages with_multilib_list with_multilib_generator +with_cmodel with_zstd with_zstd_include with_zstd_lib @@ -1880,6 +1881,7 @@ Optional Packages: SH and x86-64 only) --with-multilib-generator Multi-libs configuration string (RISC-V only) + --with-cmodel Code model configuration string (RISC-V only) --with-zstd=PATH specify prefix directory for installed zstd library. Equivalent to --with-zstd-include=PATH/include plus --with-zstd-lib=PATH/lib @@ -8381,6 +8383,15 @@ else fi + +# Check whether --with-cmodel was given. +if test "${with_cmodel+set}" = set; then : + withval=$with_cmodel; : +else + with_cmodel=medlow +fi + + # ------------------------- # Checks for other programs # ------------------------- @@ -21406,7 +21417,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 21409 "configure" +#line 21420 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -21512,7 +21523,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 21515 "configure" +#line 21526 "configure" #include "confdefs.h" #if HAVE_DLFCN_H diff --git a/gcc/configure.ac b/gcc/configure.ac index eaa01d0d7e5..1339bb2ba3b 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -1212,6 +1212,11 @@ AC_ARG_WITH(multilib-generator, :, with_multilib_generator=default) +AC_ARG_WITH(cmodel, +[AS_HELP_STRING([--with-cmodel], [Code model configuration string (RISC-V only)])], +:, +with_cmodel=medlow) + # ------------------------- # Checks for other programs # ------------------------- diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index 4973f195daf..53f8dd21e37 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -1519,6 +1519,10 @@ Use big endian by default. Provide a multilib for little endian. Use little endian by default. Provide a multilib for big endian. @end table +@item --with-cmodel=@var{cmodel} +Specify what code model to use by default. +Currently only implemented for riscv*-*-*. + @item --enable-threads Specify that the target supports threads. This affects the Objective-C compiler and runtime diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 54ecd9a00eb..f219cd3db19 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -31285,8 +31285,10 @@ element-misaligned vector memory access. @item -mcmodel=medlow Generate code for the medium-low code model. The program and its statically defined symbols must lie within a single 2 GiB address range and must lie -between absolute addresses @minus{}2 GiB and +2 GiB. Programs can be -statically or dynamically linked. This is the default code model. +between absolute addresses @minus{}2 GiB and +2 GiB. Programs can be statically +or dynamically linked. This is the default code model unless GCC has been +configured with @option{--with-cmodel=} specifying a different default code +model. @opindex mcmodel=medany @item -mcmodel=medany