https://gcc.gnu.org/g:99f7764e0b7cf28fa22a875320de0cf22c3d5025

commit 99f7764e0b7cf28fa22a875320de0cf22c3d5025
Author: Thomas Schwinge <tschwi...@baylibre.com>
Date:   Mon Dec 2 16:50:16 2024 +0100

    'gcc/config/nvptx/gen-multilib-matches.sh': Support '--selftest'
    
    ..., and invoke that before actual use.
    
            gcc/
            * config/nvptx/gen-multilib-matches.sh: Support '--selftest'.
            * config/nvptx/t-nvptx (t-nvptx-gen-multilib-matches:): Invoke it.
            * config/nvptx/gen-multilib-matches-tests: New.
    
    (cherry picked from commit ccd6ec23177f7a4ed69fabad8e79d5d4da419fb2)

Diff:
---
 gcc/ChangeLog.omp                           |  7 +++
 gcc/config/nvptx/gen-multilib-matches-tests | 77 +++++++++++++++++++++++++++
 gcc/config/nvptx/gen-multilib-matches.sh    | 82 ++++++++++++++++++++++++++++-
 gcc/config/nvptx/t-nvptx                    |  2 +
 4 files changed, 166 insertions(+), 2 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 027cb8ac02ea..81cffa1a2758 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -3,6 +3,13 @@
        Backported from trunk:
        2024-12-06  Thomas Schwinge  <tschwi...@baylibre.com>
 
+       * config/nvptx/gen-multilib-matches.sh: Support '--selftest'.
+       * config/nvptx/t-nvptx (t-nvptx-gen-multilib-matches:): Invoke it.
+       * config/nvptx/gen-multilib-matches-tests: New.
+
+       Backported from trunk:
+       2024-12-06  Thomas Schwinge  <tschwi...@baylibre.com>
+
        * config/nvptx/gen-h.sh: Don't pass in '$1'; compute it locally.
        * config/nvptx/gen-multilib-matches.sh: Likewise.
        * config/nvptx/gen-omp-device-properties.sh: Likewise.
diff --git a/gcc/config/nvptx/gen-multilib-matches-tests 
b/gcc/config/nvptx/gen-multilib-matches-tests
new file mode 100644
index 000000000000..c2775f268354
--- /dev/null
+++ b/gcc/config/nvptx/gen-multilib-matches-tests
@@ -0,0 +1,77 @@
+# Test cases for 'gen-multilib-matches.sh'.
+
+# Blank lines and lines beginning with '#' are ignored.
+
+# 'BEGIN [name]': clear state, begin test [name].
+# 'SSMS 30 35 53': set 'sms' to '30 35 53'.  Default: per 'nvptx-sm.def'.
+# 'SMOID sm_30': set 'multilib_options_isa_default' to 'sm_30'.  Default: 
unset.
+# 'SMOIL sm_35 sm_30': set 'multilib_options_isa_list' to 'sm_35 sm_30'.  
Default: unset.
+# 'AEMM .=misa?sm_30': append '.=misa?sm_30' to expected "multilib matches".  
Default: unset.
+# 'CMMC': compute "multilib matches" per the current settings, and compare to 
the expected.
+
+
+BEGIN '--with-arch=sm_30'
+SMOID sm_30
+SMOIL sm_30
+AEMM .=misa?sm_30
+AEMM .=misa?sm_35
+AEMM .=misa?sm_53
+AEMM .=misa?sm_70
+AEMM .=misa?sm_75
+AEMM .=misa?sm_80
+CMMC
+
+
+BEGIN '--with-arch=sm_35'
+SMOID sm_35
+SMOIL sm_35 sm_30
+AEMM .=misa?sm_35
+AEMM .=misa?sm_53
+AEMM .=misa?sm_70
+AEMM .=misa?sm_75
+AEMM .=misa?sm_80
+CMMC
+
+
+BEGIN '--with-arch=sm_53'
+SMOID sm_53
+SMOIL sm_53 sm_30
+AEMM misa?sm_30=misa?sm_35
+AEMM .=misa?sm_53
+AEMM .=misa?sm_70
+AEMM .=misa?sm_75
+AEMM .=misa?sm_80
+CMMC
+
+
+BEGIN '--with-arch=sm_70'
+SMOID sm_70
+SMOIL sm_70 sm_30
+AEMM misa?sm_30=misa?sm_35
+AEMM misa?sm_30=misa?sm_53
+AEMM .=misa?sm_70
+AEMM .=misa?sm_75
+AEMM .=misa?sm_80
+CMMC
+
+
+BEGIN '--with-arch=sm_75'
+SMOID sm_75
+SMOIL sm_75 sm_30
+AEMM misa?sm_30=misa?sm_35
+AEMM misa?sm_30=misa?sm_53
+AEMM misa?sm_30=misa?sm_70
+AEMM .=misa?sm_75
+AEMM .=misa?sm_80
+CMMC
+
+
+BEGIN '--with-arch=sm_80'
+SMOID sm_80
+SMOIL sm_80 sm_30
+AEMM misa?sm_30=misa?sm_35
+AEMM misa?sm_30=misa?sm_53
+AEMM misa?sm_30=misa?sm_70
+AEMM misa?sm_30=misa?sm_75
+AEMM .=misa?sm_80
+CMMC
diff --git a/gcc/config/nvptx/gen-multilib-matches.sh 
b/gcc/config/nvptx/gen-multilib-matches.sh
index 09761a9e6907..f6f2ed079f68 100755
--- a/gcc/config/nvptx/gen-multilib-matches.sh
+++ b/gcc/config/nvptx/gen-multilib-matches.sh
@@ -27,6 +27,7 @@ nvptx_dir=$(dirname "$0")
 
 
 nvptx_sm_def="$nvptx_dir/nvptx-sm.def"
+gen_multilib_matches_tests="$nvptx_dir/gen-multilib-matches-tests"
 
 sms=$(grep ^NVPTX_SM $nvptx_sm_def | sed 's/.*(//;s/,.*//')
 
@@ -88,5 +89,82 @@ print_multilib_matches() {
     echo "$multilib_matches"
 }
 
-multilib_matches=$(print_multilib_matches "$sms" "$@")
-echo "multilib_matches := $multilib_matches"
+
+selftest() {
+    [ $# = 0 ]
+
+    local sms_default
+    sms_default=$sms
+
+    local name
+    unset name
+    local sms
+    unset sms
+    local multilib_options_isa_default
+    unset multilib_options_isa_default
+    local multilib_options_isa_list
+    unset multilib_options_isa_list
+    local multilib_matches_expected
+    unset multilib_matches_expected
+
+    local line
+    line=0
+    local f1 f2
+    unset f1 f2
+    while read -r f1 f2; do
+       line=$((line + 1))
+       case "$f1 $f2" in
+           ' ' | '#'* )
+               :
+               ;;
+           'BEGIN '* )
+               name=$f2
+               sms=$sms_default
+               unset multilib_options_isa_default
+               unset multilib_options_isa_list
+               unset multilib_matches_expected
+               ;;
+           'SSMS '* )
+               sms=$f2
+               ;;
+           'SMOID '* )
+               multilib_options_isa_default=$f2
+               ;;
+           'SMOIL '* )
+               multilib_options_isa_list=$f2
+               ;;
+           'AEMM '* )
+               multilib_matches_expected="$multilib_matches_expected $f2"
+               ;;
+           'CMMC ' )
+               local multilib_matches
+               multilib_matches=$(print_multilib_matches "${sms?}" 
"${multilib_options_isa_default?}" "${multilib_options_isa_list?}")
+               if [ "$multilib_matches" = "$multilib_matches_expected" ]; then
+                   echo >&2 "$0": selftest PASS "${name?}" at 
"$gen_multilib_matches_tests:$line"
+               else
+                   echo >&2 "$0": selftest FAIL "${name?}" at 
"$gen_multilib_matches_tests:$line"
+                   echo >&2 expected:"$multilib_matches_expected"
+                   echo >&2 actual:"$multilib_matches"
+                   exit 1
+               fi
+               ;;
+           * )
+               echo >&2 "$0": selftest ERROR at 
"$gen_multilib_matches_tests:$line"
+               echo >&2 invalid directive: "$f1 $f2"
+               exit 1
+               ;;
+       esac
+    done < "$gen_multilib_matches_tests"
+}
+
+
+case "${1?}" in
+    --selftest )
+       shift
+       selftest "$@"
+       :;;
+    * )
+       multilib_matches=$(print_multilib_matches "$sms" "$@")
+       echo "multilib_matches := $multilib_matches"
+       ;;
+esac
diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index 00a7b15496e0..563c7b30dab2 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -48,6 +48,8 @@ t-nvptx-gen-multilib-matches: 
$(srcdir)/config/nvptx/gen-multilib-matches.sh \
   $(srcdir)/config/nvptx/t-nvptx \
   Makefile \
   $(srcdir)/config/nvptx/nvptx-sm.def
+       $(SHELL) $< \
+         --selftest
        $(SHELL) $< \
          $(multilib_options_isa_default) \
          '$(multilib_options_isa_list)' \

Reply via email to