[clang] [lld] [llvm] Test: Fix tests for normalization of triple XXX-none-ABI. NFC (PR #90313)

2024-04-26 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

Blocked by https://github.com/llvm/llvm-project/pull/89638

https://github.com/llvm/llvm-project/pull/90313
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] Test: Fix tests for normalization of triple XXX-none-ABI. NFC (PR #90313)

2024-04-26 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa converted_to_draft 
https://github.com/llvm/llvm-project/pull/90313
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] Test: Fix tests for normalization of triple XXX-none-ABI. NFC (PR #90313)

2024-04-26 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/90313

https://discourse.llvm.org/t/rfc-baremetal-target-triple-normalization/78524

See: PR#89638.

>From 28b918f8a67381cd568c85bae77af517091a32b4 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Sat, 27 Apr 2024 13:14:02 +0800
Subject: [PATCH] Test: Fix tests for normalization of triple XXX-none-ABI. NFC

https://discourse.llvm.org/t/rfc-baremetal-target-triple-normalization/78524
See: PR#89638.
---
 .../test/CodeGen/Inputs/linker-diagnostic1.ll |  2 +-
 clang/test/CodeGen/linker-diagnostic.ll   |  4 +-
 clang/test/Driver/arm-ias-Wa.s|  2 +-
 clang/test/Driver/arm-triple.c| 10 +--
 .../baremetal-multilib-exclusive-group.yaml   | 22 +++
 .../baremetal-multilib-group-error.yaml   |  4 +-
 .../Driver/baremetal-multilib-layered.yaml|  2 +-
 clang/test/Driver/baremetal-multilib.yaml | 64 +--
 clang/test/Driver/baremetal-sysroot.cpp   |  2 +-
 clang/test/Driver/baremetal.cpp   |  2 +-
 .../test/Driver/print-multi-selection-flags.c | 14 ++--
 clang/test/Preprocessor/init-arm.c|  4 +-
 clang/unittests/Driver/MultilibTest.cpp   | 52 +++
 .../IncrementalCompilerBuilderTest.cpp|  2 +-
 lld/test/ELF/lto/arm.ll   |  4 +-
 .../CodeGen/ARM/machine-sink-multidef.mir |  2 +-
 llvm/test/CodeGen/ARM/store-prepostinc.mir|  2 +-
 .../CodeGen/ARM/unschedule-reg-sequence.ll|  2 +-
 .../Thumb/consthoist-few-dependents.ll|  2 +-
 .../CodeGen/Thumb/consthoist-imm8-costs-1.ll  |  2 +-
 llvm/test/CodeGen/Thumb/pr42760.ll|  2 +-
 llvm/test/CodeGen/Thumb/smul_fix.ll   |  2 +-
 llvm/test/CodeGen/Thumb/smul_fix_sat.ll   |  2 +-
 llvm/test/CodeGen/Thumb/umul_fix.ll   |  2 +-
 llvm/test/CodeGen/Thumb/umul_fix_sat.ll   |  2 +-
 .../Thumb2/LowOverheadLoops/spillingmove.mir  |  2 +-
 .../LowOverheadLoops/wls-search-pred.mir  |  2 +-
 llvm/test/CodeGen/Thumb2/high-reg-spill.mir   |  2 +-
 .../CodeGen/Thumb2/mve-pred-constfold.mir |  2 +-
 .../CodeGen/Thumb2/mve-vpt-block-debug.mir|  2 +-
 .../Thumb2/pipeliner-preserve-ties.mir|  2 +-
 llvm/test/CodeGen/Thumb2/store-prepostinc.mir |  2 +-
 .../InferFunctionAttrs/norecurse_debug.ll |  2 +-
 .../ARM/mve-hoist-runtime-checks.ll   |  2 +-
 llvm/unittests/TargetParser/TripleTest.cpp|  2 +-
 35 files changed, 115 insertions(+), 115 deletions(-)

diff --git a/clang/test/CodeGen/Inputs/linker-diagnostic1.ll 
b/clang/test/CodeGen/Inputs/linker-diagnostic1.ll
index 913dbefe5ccec9..96883aa26cffed 100644
--- a/clang/test/CodeGen/Inputs/linker-diagnostic1.ll
+++ b/clang/test/CodeGen/Inputs/linker-diagnostic1.ll
@@ -1,4 +1,4 @@
-target triple = "armv4-none-unknown-eabi"
+target triple = "armv4-unknown-none-eabi"
 target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
 
 declare i32 @foo(i32)
diff --git a/clang/test/CodeGen/linker-diagnostic.ll 
b/clang/test/CodeGen/linker-diagnostic.ll
index c8406314f8d6fd..009819b464fe50 100644
--- a/clang/test/CodeGen/linker-diagnostic.ll
+++ b/clang/test/CodeGen/linker-diagnostic.ll
@@ -4,10 +4,10 @@
 ; RUN: opt -module-summary -o %t/bar.o %S/Inputs/linker-diagnostic1.ll
 ; RUN: llvm-lto2 run --thinlto-distributed-indexes -r %t/foo.o,foo,plx -r 
%t/bar.o,bar,plx \
 ; RUN:   -r %t/bar.o,foo, -o %t/foobar.so %t/foo.o %t/bar.o
-; RUN: %clang -c -o %t/lto.bar.o --target=armv4-none-unknown-eabi -O2 \
+; RUN: %clang -c -o %t/lto.bar.o --target=armv4-unknown-none-eabi -O2 \
 ; RUN:   -fthinlto-index=%t/bar.o.thinlto.bc %t/bar.o -Wno-override-module 
2>&1 | FileCheck %s
 
-; CHECK: linking module '{{.*}}/bar.o': Linking two modules of different 
target triples: '{{.*}}/foo.o' is 'thumbv6-unknown-linux-gnueabihf' whereas 
'{{.*}}/bar.o' is 'armv4-none-unknown-eabi'
+; CHECK: linking module '{{.*}}/bar.o': Linking two modules of different 
target triples: '{{.*}}/foo.o' is 'thumbv6-unknown-linux-gnueabihf' whereas 
'{{.*}}/bar.o' is 'armv4-unknown-none-eabi'
 
 target triple = "thumbv6-unknown-linux-gnueabihf"
 target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
diff --git a/clang/test/Driver/arm-ias-Wa.s b/clang/test/Driver/arm-ias-Wa.s
index b82ce8dfb31ab3..5e9518ed2dc423 100644
--- a/clang/test/Driver/arm-ias-Wa.s
+++ b/clang/test/Driver/arm-ias-Wa.s
@@ -71,7 +71,7 @@
 
 // RUN: %clang -target armv7r-none-eabi -c %s -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-R-PROFILE %s
-// CHECK-R-PROFILE: "-triple" "armv7r-none-unknown-eabi"
+// CHECK-R-PROFILE: "-triple" "armv7r-unknown-none-eabi"
 
 // RUN: %clang -target armv7m-none-eabi -c %s -### 2>&1 \
 // RUN: %clang -target thumbv7m-none-eabi -c %s -### 2>&1 \
diff --git a/clang/test/Driver/arm-triple.c b/clang/test/Driver/arm-triple.c
index fa9f7b189c8278..1fb2b5afe22a51 100644
--- a/clang/test/Driver/arm-triple.c
+++ b/clang/test/Driver/arm-triple.c
@@ -7,7 +7,7 @@
 // 

[clang] [libcxx] [llvm] Triple::normalize: Use none as OS for XX-none-ABI (PR #89638)

2024-04-26 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/89638
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [llvm] Triple::normalize: Use none as OS for XX-none-ABI (PR #89638)

2024-04-26 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/89638
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [llvm] Triple::normalize: Triple::normalize: Use none as OS for XX-none-ABI (PR #89638)

2024-04-26 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/89638
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-26 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/89638
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-26 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa ready_for_review 
https://github.com/llvm/llvm-project/pull/89638
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-26 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/89638

>From aafa018b3d7657483738fa91812e3e8bbdd8205a Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Sat, 27 Apr 2024 10:55:38 +0800
Subject: [PATCH] Triple::normalize: Use none as OS for XX-none-ABI

When we parse 3-components triples, if the Arch and Env have been
parsed successfully, we have to make a choice between Vendor and
OS for the unrecoginzed component. Noramlly it is the middle one.

In the current code, Vendor is choosed, and then OS is fallbacked
to unknown. It is OK for most cases. But if the unrecoginzed
component is `none`, it is expected to be OS instead of Vendor.

Fixes: #89582.
---
 clang/docs/Multilib.rst  | 4 ++--
 libcxx/utils/ci/run-buildbot | 2 +-
 llvm/lib/TargetParser/Triple.cpp | 7 +++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/docs/Multilib.rst b/clang/docs/Multilib.rst
index ab737e43b97d23..063fe9a336f2fe 100644
--- a/clang/docs/Multilib.rst
+++ b/clang/docs/Multilib.rst
@@ -188,9 +188,9 @@ For a more comprehensive example see
   - Dir: thumb/v6-m
 # List of one or more normalized command line options, as generated by 
Clang
 # from the command line options or from Mappings below.
-# Here, if the flags are a superset of {target=thumbv6m-none-unknown-eabi}
+# Here, if the flags are a superset of {target=thumbv6m-unknown-none-eabi}
 # then this multilib variant will be considered a match.
-Flags: [--target=thumbv6m-none-unknown-eabi]
+Flags: [--target=thumbv6m-unknown-none-eabi]
 
   # Similarly, a multilib variant targeting Arm v7-M with an FPU (floating
   # point unit).
diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index 60307a7d4f350a..3523a29e4f4613 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -217,7 +217,7 @@ function test-armv7m-picolibc() {
 "${@}"
 
 ${NINJA} -vC "${BUILD_DIR}/compiler-rt" install
-mv "${BUILD_DIR}/install/lib/armv7m-none-unknown-eabi"/* 
"${BUILD_DIR}/install/lib"
+mv "${BUILD_DIR}/install/lib/armv7m-unknown-none-eabi"/* 
"${BUILD_DIR}/install/lib"
 
 check-runtimes
 }
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 2c5aee3dfb2f3e..9c04574fe1e4bc 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1151,6 +1151,13 @@ std::string Triple::normalize(StringRef Str) {
 }
   }
 
+  // For 3-component triples, the middle component is used to set Vendor;
+  // while if it is "none", we'd prefer to set OS.
+  // This is for some baremetal cases, such as "arm-none-elf".
+  if (Found[0] && !Found[1] && !Found[2] && Found[3] &&
+  Components[1].equals("none") && Components[2].empty())
+std::swap(Components[1], Components[2]);
+
   // Replace empty components with "unknown" value.
   for (StringRef  : Components)
 if (C.empty())

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)

2024-04-23 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

> 
> Sure. The motivation on our side is a distributed compile service where the 
> library doesn't exist on the remote end. This patch means we'll have to add 
> knowledge about path layouts at link time to the remote setup at compile 
> time. That's certainly doable, but kind of janky.
> 

I guess `using new-style always` can make things simpler. Since you won't need 
to know how to convert the target name to tail arch name. For every arch, it 
uses the same archive file name.

Does your `distributed compile service` is like:
1. Use upload C/C++ code
2. Your service compiles them to ASM code.
3. User downloads the ASM code
4. User assembles and link
If so, it will always have a trouble for any case, as the archive's filename 
differs between users local setup.
I think that problem is a chaos during the transition.
In fact, a filename like `clang_rt.profile-x86_64.lib` also contains info about 
path layout at compile time.
What you really need is an option for user to tell us their local path layout.

https://github.com/llvm/llvm-project/pull/87866
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [lld] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread YunQiang Su via cfe-commits


@@ -1149,6 +1149,13 @@ std::string Triple::normalize(StringRef Str) {
 }
   }
 
+  // For 3-component triples, the middle component is used to set Vendor;
+  // while if it is "none", we'd prefer to set OS.
+  // This is for some baremetal cases, such as "arm-none-elf".
+  if (Found[0] && !Found[1] && !Found[2] && Found[3] &&
+  Components[1].equals("none") && Components[2].empty())
+std::swap(Components[1], Components[2]);

wzssyqa wrote:

Sure. we can. I think that we may need more update to `Triple::normalize`. Once 
we can decide how to normalize `aarch64-none-elf`, then I will split this PR.

https://github.com/llvm/llvm-project/pull/89638
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [lld] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

> I've just posted an RFC to discourse about how to handle triple 
> normalization: 
> https://discourse.llvm.org/t/rfc-baremetal-target-triple-normalization/78524

We don't need to revert https://github.com/llvm/llvm-project/pull/89234
It is easy to fix `Triple::normalize` once you decide how to normalize your 
triples.
I will help to do so.

https://github.com/llvm/llvm-project/pull/89638
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)

2024-04-23 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

Will the contents of `empty.asm` correct if `lib//clang_rt.profile.lib` 
doesn't exist?
I mean, will `empty.asm` contains `/DEFAULTLIB:clang_rt.profile-x86_64.lib` 
then?

https://github.com/llvm/llvm-project/pull/87866
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [lld] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

@llvm/pr-subscribers-backend-arm @llvm/pr-subscribers-backend-aarch64 

https://github.com/llvm/llvm-project/pull/89638
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [lld] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/89638

>From 11ae27aeb512b661a3423a8b92642a9ec08ca6a1 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Apr 2024 01:36:17 +0800
Subject: [PATCH] Triple::normalize: Set OS for 3-component triple with none as
 middle

If the middle component of a 3-component triple fails to parse as known
Arch/Vendor/OS/Env, it will fallback as Vendor. While for some cases,
we may wish to recognize it as OS, such as `arm64-none-elf`.

In this patch, we will set OS as `none`, if:
1) Arch is found;
2) Env is found;
3) OS is not found and thus is set as empty;
4) Vendor is not found while is set as "none",
we will swap Component[2] and Component[3].

Use this new triple for these tests:
  - clang/docs/Multilib.rst
  - clang/test/CodeGen/Inputs/linker-diagnostic1.ll
  - clang/test/CodeGen/linker-diagnostic.ll
  - clang/test/Driver/arm-ias-Wa.s
  - clang/test/Driver/arm-triple.c
  - clang/test/Driver/baremetal-multilib-exclusive-group.yaml
  - clang/test/Driver/baremetal-multilib-group-error.yaml
  - clang/test/Driver/baremetal-multilib-layered.yaml
  - clang/test/Driver/baremetal-multilib.yaml
  - clang/test/Driver/baremetal-sysroot.cpp
  - clang/test/Driver/baremetal.cpp
  - clang/test/Driver/print-multi-selection-flags.c
  - clang/test/Driver/program-path-priority.c
  - clang/test/Preprocessor/init-arm.c
  - clang/unittests/Driver/MultilibTest.cpp
  - clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
  - libcxx/utils/ci/run-buildbot
  - lld/test/ELF/lto/arm.ll
  - llvm/test/CodeGen/ARM/machine-sink-multidef.mir
  - llvm/test/CodeGen/ARM/store-prepostinc.mir
  - llvm/test/CodeGen/ARM/unschedule-reg-sequence.ll
  - llvm/test/CodeGen/Thumb/consthoist-few-dependents.ll
  - llvm/test/CodeGen/Thumb/consthoist-imm8-costs-1.ll
  - llvm/test/CodeGen/Thumb/pr42760.ll
  - llvm/test/CodeGen/Thumb/smul_fix.ll
  - llvm/test/CodeGen/Thumb/smul_fix_sat.ll
  - llvm/test/CodeGen/Thumb/umul_fix.ll
  - llvm/test/CodeGen/Thumb/umul_fix_sat.ll
  - llvm/test/CodeGen/Thumb2/LowOverheadLoops/spillingmove.mir
  - llvm/test/CodeGen/Thumb2/LowOverheadLoops/wls-search-pred.mir
  - llvm/test/CodeGen/Thumb2/high-reg-spill.mir
  - llvm/test/CodeGen/Thumb2/mve-pred-constfold.mir
  - llvm/test/CodeGen/Thumb2/mve-vpt-block-debug.mir
  - llvm/test/CodeGen/Thumb2/pipeliner-preserve-ties.mir
  - llvm/test/CodeGen/Thumb2/store-prepostinc.mir
  - llvm/test/Transforms/InferFunctionAttrs/norecurse_debug.ll
  - llvm/test/Transforms/LoopVectorize/ARM/mve-hoist-runtime-checks.ll
  - llvm/unittests/TargetParser/TripleTest.cpp

Fixes: #89582.
---
 clang/docs/Multilib.rst   |  4 +-
 .../test/CodeGen/Inputs/linker-diagnostic1.ll |  2 +-
 clang/test/CodeGen/linker-diagnostic.ll   |  4 +-
 clang/test/Driver/arm-ias-Wa.s|  2 +-
 clang/test/Driver/arm-triple.c| 10 +--
 .../baremetal-multilib-exclusive-group.yaml   | 22 +++
 .../baremetal-multilib-group-error.yaml   |  4 +-
 .../Driver/baremetal-multilib-layered.yaml|  2 +-
 clang/test/Driver/baremetal-multilib.yaml | 64 +--
 clang/test/Driver/baremetal-sysroot.cpp   |  2 +-
 clang/test/Driver/baremetal.cpp   |  2 +-
 .../test/Driver/print-multi-selection-flags.c | 14 ++--
 clang/test/Driver/program-path-priority.c |  4 +-
 clang/test/Preprocessor/init-arm.c|  4 +-
 clang/unittests/Driver/MultilibTest.cpp   | 52 +++
 .../IncrementalCompilerBuilderTest.cpp|  2 +-
 libcxx/utils/ci/run-buildbot  |  2 +-
 lld/test/ELF/lto/arm.ll   |  4 +-
 llvm/lib/TargetParser/Triple.cpp  |  7 ++
 .../CodeGen/ARM/machine-sink-multidef.mir |  2 +-
 llvm/test/CodeGen/ARM/store-prepostinc.mir|  2 +-
 .../CodeGen/ARM/unschedule-reg-sequence.ll|  2 +-
 .../Thumb/consthoist-few-dependents.ll|  2 +-
 .../CodeGen/Thumb/consthoist-imm8-costs-1.ll  |  2 +-
 llvm/test/CodeGen/Thumb/pr42760.ll|  2 +-
 llvm/test/CodeGen/Thumb/smul_fix.ll   |  2 +-
 llvm/test/CodeGen/Thumb/smul_fix_sat.ll   |  2 +-
 llvm/test/CodeGen/Thumb/umul_fix.ll   |  2 +-
 llvm/test/CodeGen/Thumb/umul_fix_sat.ll   |  2 +-
 .../Thumb2/LowOverheadLoops/spillingmove.mir  |  2 +-
 .../LowOverheadLoops/wls-search-pred.mir  |  2 +-
 llvm/test/CodeGen/Thumb2/high-reg-spill.mir   |  2 +-
 .../CodeGen/Thumb2/mve-pred-constfold.mir |  2 +-
 .../CodeGen/Thumb2/mve-vpt-block-debug.mir|  2 +-
 .../Thumb2/pipeliner-preserve-ties.mir|  2 +-
 llvm/test/CodeGen/Thumb2/store-prepostinc.mir |  2 +-
 .../InferFunctionAttrs/norecurse_debug.ll |  2 +-
 .../ARM/mve-hoist-runtime-checks.ll   |  2 +-
 llvm/unittests/TargetParser/TripleTest.cpp|  2 +-
 39 files changed, 127 insertions(+), 120 deletions(-)

diff --git a/clang/docs/Multilib.rst b/clang/docs/Multilib.rst
index ab737e43b97d23..063fe9a336f2fe 

[clang] [libcxx] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa converted_to_draft 
https://github.com/llvm/llvm-project/pull/89638
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

@peterwaller-arm Ohh, there is so many `-none-unknown-` in current code. I 
guess it may be widely used.
Do we really want to change all of them?

https://github.com/llvm/llvm-project/pull/89638
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/89638
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

2024-04-23 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/89638

>From a40bf92dcdaa64c2ca73d9276972c8cd47750210 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Apr 2024 01:36:17 +0800
Subject: [PATCH] Triple::normalize: Set OS for 3-component triple with none as
 middle

If the middle component of a 3-component triple fails to parse as known
Arch/Vendor/OS/Env, it will fallback as Vendor. While for some cases,
we may wish to recognize it as OS, such as `arm64-none-elf`.

In this patch, we will set OS as `none`, if:
1) Arch is found;
2) Env is found;
3) OS is not found and thus is set as empty;
4) Vendor is not found while is set as "none",
we will swap Component[2] and Component[3].

Use this new triple for these tests:
  - libcxx/utils/ci/run-buildbot
  - clang/test/Driver/print-multi-selection-flags.c
  - llvm/unittests/TargetParser/TripleTest.cpp

Fixes: #89582.
---
 clang/test/Driver/print-multi-selection-flags.c | 14 +++---
 libcxx/utils/ci/run-buildbot|  2 +-
 llvm/lib/TargetParser/Triple.cpp|  7 +++
 llvm/unittests/TargetParser/TripleTest.cpp  |  2 +-
 4 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/clang/test/Driver/print-multi-selection-flags.c 
b/clang/test/Driver/print-multi-selection-flags.c
index 06a12db9d97792..9f58d1b557fd74 100644
--- a/clang/test/Driver/print-multi-selection-flags.c
+++ b/clang/test/Driver/print-multi-selection-flags.c
@@ -5,27 +5,27 @@
 // CHECK-FUCHSIA: --target=aarch64-unknown-fuchsia
 
 // RUN: %clang -print-multi-flags-experimental --target=arm-none-eabi 
-mfloat-abi=soft -fno-exceptions -fno-rtti | FileCheck 
--check-prefix=CHECK-ARMV4T %s
-// CHECK-ARMV4T: --target=armv4t-none-unknown-eabi
+// CHECK-ARMV4T: --target=armv4t-unknown-none-eabi
 // CHECK-ARMV4T: -mfloat-abi=soft
 // CHECK-ARMV4T: -mfpu=none
 
 // RUN: %clang -print-multi-flags-experimental --target=armv7em-none-eabi 
-mfloat-abi=softfp | FileCheck --check-prefix=CHECK-SOFTFP %s
-// CHECK-SOFTFP: --target=thumbv7em-none-unknown-eabi
+// CHECK-SOFTFP: --target=thumbv7em-unknown-none-eabi
 // CHECK-SOFTFP: -mfloat-abi=softfp
 // CHECK-SOFTFP: -mfpu=fpv4-sp-d16
 
 // RUN: %clang -print-multi-flags-experimental --target=arm-none-eabihf 
-march=armv7em -mfpu=fpv5-d16 | FileCheck --check-prefix=CHECK-HARD %s
-// CHECK-HARD: --target=thumbv7em-none-unknown-eabihf
+// CHECK-HARD: --target=thumbv7em-unknown-none-eabihf
 // CHECK-HARD: -mfloat-abi=hard
 // CHECK-HARD: -mfpu=fpv5-d16
 
 // RUN: %clang -print-multi-flags-experimental --target=arm-none-eabi 
-mfloat-abi=soft -march=armv8-m.main+nofp | FileCheck 
--check-prefix=CHECK-V8MMAIN-NOFP %s
-// CHECK-V8MMAIN-NOFP: --target=thumbv8m.main-none-unknown-eabi
+// CHECK-V8MMAIN-NOFP: --target=thumbv8m.main-unknown-none-eabi
 // CHECK-V8MMAIN-NOFP: -mfloat-abi=soft
 // CHECK-V8MMAIN-NOFP: -mfpu=none
 
 // RUN: %clang -print-multi-flags-experimental --target=arm-none-eabi 
-mfloat-abi=hard -march=armv8.1m.main+mve.fp | FileCheck 
--check-prefix=CHECK-MVE %s
-// CHECK-MVE: --target=thumbv8.1m.main-none-unknown-eabihf
+// CHECK-MVE: --target=thumbv8.1m.main-unknown-none-eabihf
 // CHECK-MVE: -march=thumbv8.1m.main{{.*}}+mve{{.*}}+mve.fp{{.*}}
 // CHECK-MVE: -mfloat-abi=hard
 // CHECK-MVE: -mfpu=fp-armv8-fullfp16-sp-d16
@@ -51,10 +51,10 @@
 // CHECK-M85_NO_FP_DP: -mfpu=fp-armv8-fullfp16-sp-d16
 
 // RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf 
-march=armv8-a+lse | FileCheck --check-prefix=CHECK-LSE %s
-// CHECK-LSE: --target=aarch64-none-unknown-elf
+// CHECK-LSE: --target=aarch64-unknown-none-elf
 // CHECK-LSE: -march=armv8-a{{.*}}+lse{{.*}}
 
 // RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf 
-march=armv8.5-a+sve+sve2 | FileCheck --check-prefix=CHECK-SVE2 %s
 // RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf 
-march=armv9-a| FileCheck --check-prefix=CHECK-SVE2 %s
-// CHECK-SVE2: --target=aarch64-none-unknown-elf
+// CHECK-SVE2: --target=aarch64-unknown-none-elf
 // CHECK-SVE2: -march=armv{{.*}}-a{{.*}}+simd{{.*}}+sve{{.*}}+sve2{{.*}}
diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index 60307a7d4f350a..3523a29e4f4613 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -217,7 +217,7 @@ function test-armv7m-picolibc() {
 "${@}"
 
 ${NINJA} -vC "${BUILD_DIR}/compiler-rt" install
-mv "${BUILD_DIR}/install/lib/armv7m-none-unknown-eabi"/* 
"${BUILD_DIR}/install/lib"
+mv "${BUILD_DIR}/install/lib/armv7m-unknown-none-eabi"/* 
"${BUILD_DIR}/install/lib"
 
 check-runtimes
 }
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 77fdf31d4865c0..07f3df4145dad4 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1149,6 +1149,13 @@ std::string Triple::normalize(StringRef Str) {
 }
   }
 
+  // For 3-component triples, 

[clang] [Driver] Improve error when a compiler-rt library is not found (PR #81037)

2024-04-22 Thread YunQiang Su via cfe-commits


@@ -656,19 +656,29 @@ std::string ToolChain::getCompilerRT(const ArgList , 
StringRef Component,
   // Check for runtime files in the new layout without the architecture first.
   std::string CRTBasename =
   buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
+  SmallString<128> Path;
   for (const auto  : getLibraryPaths()) {
 SmallString<128> P(LibPath);
 llvm::sys::path::append(P, CRTBasename);
 if (getVFS().exists(P))
   return std::string(P);
+if (Path.empty())
+  Path = P;
   }
+  if (getTriple().isOSAIX())
+Path.clear();
 
-  // Fall back to the old expected compiler-rt name if the new one does not
-  // exist.
+  // Check the filename for the old layout if the new one does not exist.
   CRTBasename =
   buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/true);
-  SmallString<128> Path(getCompilerRTPath());
-  llvm::sys::path::append(Path, CRTBasename);
+  SmallString<128> OldPath(getCompilerRTPath());
+  llvm::sys::path::append(OldPath, CRTBasename);
+  if (Path.empty() || getVFS().exists(OldPath))
+return std::string(OldPath);
+
+  // If none is found, use a file name from the new layout, which may get
+  // printed in an error message, aiding users in knowing what Clang is
+  // looking for.

wzssyqa wrote:

It is only about warning msg.
Clang will try to find libraries for both new and old style paths.

If you'd like to put the libraries in old style path/filename, you can use 
`-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF`.

Of course, even with the above configure option, if clang cannot find a 
library, it will warn with new style path.

https://github.com/llvm/llvm-project/pull/81037
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [CMake] Use Clang to infer the target triple (PR #89425)

2024-04-19 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/89425
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [CMake] Use Clang to infer the target triple (PR #89425)

2024-04-19 Thread YunQiang Su via cfe-commits


@@ -28,6 +28,19 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   if (NOT LLVM_RUNTIMES_BUILD)
 load_llvm_config()
   endif()
+  if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+set(print_target_triple ${CMAKE_CXX_COMPILER} 
--target=${LLVM_RUNTIME_TRIPLE} -print-target-triple)

wzssyqa wrote:

I am wondering that whether `CMAKE_CXX_COMPILER` is defined for 
`compiler-rt/lib/builtins`.
All source of this library is pure C/ASM.

In fact when I worked on my PR, I did meet this problem.
My configure cmd is
```
cmake ../llvm -G Ninja -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=off 
-DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-gnu -DLLVM_USE_LINKER=lld 
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libunwind" 
-DLLVM_ENABLE_PROJECTS="mlir;clang;clang-tools-extra;lld" 
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ 
-DCMAKE_BUILD_TYPE=RelWithDebInfo
```

https://github.com/llvm/llvm-project/pull/89425
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [CMake] Use Clang to infer the target triple (PR #89425)

2024-04-19 Thread YunQiang Su via cfe-commits


@@ -28,6 +28,19 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   if (NOT LLVM_RUNTIMES_BUILD)
 load_llvm_config()
   endif()
+  if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)

wzssyqa wrote:

With my patch, `libclang_rt.builtin` has been installed to per_target runtime 
dir.
I don't think that this one is needed.

And `if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR` is not needed here: it is just set 
the triple.
If `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=off`, the libraries will still install 
to non-per-target dir.

And `if(NOT APPLE)` is not needed either.
```
$ ./bin/clang --target=air64-apple-ios16.0 -print-target-triple  
air64-apple-ios16.0
$ ./bin/clang --target=arm64-apple-darwin23.4.0 -print-target-triple  
arm64-apple-darwin23.4.0
```

https://github.com/llvm/llvm-project/pull/89425
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [CMake] Use Clang to infer the target triple (PR #89425)

2024-04-19 Thread YunQiang Su via cfe-commits


@@ -181,6 +181,20 @@ message(STATUS "LLVM default target triple: 
${LLVM_DEFAULT_TARGET_TRIPLE}")
 
 set(LLVM_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
 
+if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+  set(print_target_triple ${CMAKE_CXX_COMPILER} 
--target=${LLVM_RUNTIME_TRIPLE} -print-target-triple)
+  execute_process(COMMAND ${print_target_triple}
+RESULT_VARIABLE result
+OUTPUT_VARIABLE output
+OUTPUT_STRIP_TRAILING_WHITESPACE)
+  if(result EQUAL 0)
+set(LLVM_RUNTIME_TRIPLE ${output})

wzssyqa wrote:

`LLVM_RUNTIME_TRIPLE` seem to be not used? I cannot find this symbol by `grep`.

https://github.com/llvm/llvm-project/pull/89425
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [CMake] Use Clang to infer the target triple (PR #89425)

2024-04-19 Thread YunQiang Su via cfe-commits


@@ -142,7 +142,7 @@ if(WIN32 OR LLVM_WINSYSROOT)
   set(RUNTIMES_${target}_CMAKE_MODULE_LINKER_FLAGS ${WINDOWS_LINK_FLAGS} CACHE 
STRING "")
 endif()
 
-foreach(target 
aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unknown-linux-gnu;riscv64-unknown-linux-gnu;x86_64-unknown-linux-gnu)
+foreach(target 
aarch64-linux-gnu;armv7-linux-gnueabihf;i386-linux-gnu;riscv64-linux-gnu;x86_64-linux-gnu)

wzssyqa wrote:

It seems offtopic of commit msg?
Since the normalize format of `aarch64-linux-gnu` is just 
aarch64-unknown-linux-gnu, why do we need to modify them?

https://github.com/llvm/llvm-project/pull/89425
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [CMake] Use Clang to infer the target triple (PR #89425)

2024-04-19 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/89425
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [CMake] Use Clang to infer the target triple (PR #89425)

2024-04-19 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/89425
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [CMake] Use Clang to infer the target triple (PR #89425)

2024-04-19 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

Does it really needed?

https://github.com/llvm/llvm-project/pull/89425
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)

2024-04-16 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

See: https://github.com/llvm/llvm-project/pull/87866
Can you have a try to add an extra option
```
-resource-dir=%S/Inputs/resource_dir
```

https://github.com/llvm/llvm-project/pull/87866
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #88661)

2024-04-15 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa closed 
https://github.com/llvm/llvm-project/pull/88661
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #88661)

2024-04-15 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

9f43a41db37253685c5ed428c215528eb92bbd43
1693009679313282afbed38778dd3fad62641e1b

Landed as the above commits.

https://github.com/llvm/llvm-project/pull/88661
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #88661)

2024-04-14 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/88661
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)

2024-04-14 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

New PR with my resource-dir patch: 
https://github.com/llvm/llvm-project/pull/88661

https://github.com/llvm/llvm-project/pull/87866
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #88661)

2024-04-14 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/88661

Follow-up to #81037.

ToolChain::LibraryPaths holds the new compiler-rt library directory (e.g. 
`/tmp/Debug/lib/clang/19/lib/x86_64-unknown-linux-gnu`). However, it might be 
empty when the directory does not exist (due to the `if (getVFS().exists(P))` 
change in https://reviews.llvm.org/D158475).

If neither the old/new compiler-rt library directories exists, we would suggest 
the undesired old compiler-rt file name:

```
% /tmp/Debug/bin/clang++ a.cc -fsanitize=memory -o a
ld.lld: error: cannot open 
/tmp/Debug/lib/clang/19/lib/linux/libclang_rt.msan-x86_64.a: No such file or 
directory
clang++: error: linker command failed with exit code 1 (use -v to see 
invocation)
```

With this change, we will correctly suggest the new compiler-rt file name.

Fix #87150

Pull Request: https://github.com/llvm/llvm-project/pull/87866

>From b8b5c72fefe3e9cbd9782727df75c8bb6eaeec2f Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Mon, 8 Apr 2024 16:51:34 -0700
Subject: [PATCH] Ensure ToolChain::LibraryPaths is not empty for non-Darwin

Follow-up to #81037.

ToolChain::LibraryPaths holds the new compiler-rt library directory
(e.g. `/tmp/Debug/lib/clang/19/lib/x86_64-unknown-linux-gnu`). However,
it might be empty when the directory does not exist (due to the `if
(getVFS().exists(P))` change in https://reviews.llvm.org/D158475).

If neither the old/new compiler-rt library directories exists, we would
suggest the undesired old compiler-rt file name:

```
% /tmp/Debug/bin/clang++ a.cc -fsanitize=memory -o a
ld.lld: error: cannot open 
/tmp/Debug/lib/clang/19/lib/linux/libclang_rt.msan-x86_64.a: No such file or 
directory
clang++: error: linker command failed with exit code 1 (use -v to see 
invocation)
```

With this change, we will correctly suggest the new compiler-rt file name.

Fix #87150

Pull Request: https://github.com/llvm/llvm-project/pull/87866
---
 clang/lib/Driver/ToolChain.cpp|  8 -
 clang/test/Driver/arm-compiler-rt.c   | 14 
 clang/test/Driver/cl-link.c   | 16 -
 clang/test/Driver/compiler-rt-unwind.c|  6 ++--
 clang/test/Driver/coverage-ld.c   |  8 ++---
 clang/test/Driver/instrprof-ld.c  | 16 -
 clang/test/Driver/linux-ld.c  |  8 +++--
 clang/test/Driver/mingw-sanitizers.c  | 16 -
 clang/test/Driver/msp430-toolchain.c  |  4 +--
 .../Driver/print-libgcc-file-name-clangrt.c   | 12 +++
 clang/test/Driver/print-runtime-dir.c |  6 
 clang/test/Driver/riscv32-toolchain-extra.c   |  6 ++--
 clang/test/Driver/riscv32-toolchain.c |  6 ++--
 clang/test/Driver/riscv64-toolchain-extra.c   |  6 ++--
 clang/test/Driver/riscv64-toolchain.c |  6 ++--
 clang/test/Driver/sanitizer-ld.c  | 36 +++
 clang/test/Driver/wasm-toolchain.c| 18 +-
 clang/test/Driver/wasm-toolchain.cpp  | 16 -
 clang/test/Driver/windows-cross.c | 18 +-
 clang/test/Driver/zos-ld.c| 12 +++
 .../test/Driver/msvc-dependent-lib-flags.f90  |  8 ++---
 21 files changed, 127 insertions(+), 119 deletions(-)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 03450fc0f57b93..237092ed07e5dc 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -796,7 +796,13 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
 std::optional ToolChain::getRuntimePath() const {
   SmallString<128> P(D.ResourceDir);
   llvm::sys::path::append(P, "lib");
-  return getTargetSubDirPath(P);
+  if (auto Ret = getTargetSubDirPath(P))
+return Ret;
+  // Darwin does not use per-target runtime directory.
+  if (Triple.isOSDarwin())
+return {};
+  llvm::sys::path::append(P, Triple.str());
+  return std::string(P);
 }
 
 std::optional ToolChain::getStdlibPath() const {
diff --git a/clang/test/Driver/arm-compiler-rt.c 
b/clang/test/Driver/arm-compiler-rt.c
index 5e9e528400d08e..cb6c29f48a7814 100644
--- a/clang/test/Driver/arm-compiler-rt.c
+++ b/clang/test/Driver/arm-compiler-rt.c
@@ -10,47 +10,47 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABI
-// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins-arm.a"
+// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-linux-gnueabi \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -mfloat-abi=hard -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABI-ABI
-// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins-armhf.a"
+// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-linux-gnueabihf \
 // RUN: 

[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)

2024-04-11 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

[xx.patch](https://github.com/llvm/llvm-project/files/14948921/xx.patch)

@aeubanks can you help to test this patch?

https://github.com/llvm/llvm-project/pull/87866
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)

2024-04-11 Thread YunQiang Su via cfe-commits

wzssyqa wrote:


> It's better to do some normalization in CMake.

I will try to work in CMake, then.

https://github.com/llvm/llvm-project/pull/88334
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)

2024-04-11 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

> > @aeubanks The problem is that in your configure, the libclang_rt is placed 
> > in `/lib/clang/19/lib/linux/libclang_rt.builtins-arm-android.a`, 
> > instead of 
> > `/lib/clang/19/lib/arm-unknown-linux-android/libclang_rt.builtins.a`.
> 
> The point is that both locations were supposed to be accepted, as they were 
> before - this PR was not supposed to be a policy change that affects that.

Yes. After the patch, both locations are accepted. This patch doesn't break it.
The current problem is that in some test cases, `-resource-dir` option are 
missing.

For details:
1. with `--sysroot` option, clang will try to find libclang_rt there. In the 
failure case, it fails to find.
2. then, clang try to look for libclang_rt from 
`lib/clang/19/lib/arm-unknown-android/libclang_rt.builtin.a`, and failed.
3. clang try to look for libclang_rt from 
`lib/clang/19/lib/linux/libclang_rt.builtin-arm-android.a`, and success.
 Thus the file name of libclang_rt is different with the one in test cases.
4. If 3) failed, clang will fallback to  
`lib/clang/19/lib/arm-unknown-android/libclang_rt.builtin.a`, then test case 
success.

So, we can add `-resource-dir` to skip 3 for test case.

   

https://github.com/llvm/llvm-project/pull/87866
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)

2024-04-11 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

Configure cmd
```
cmake ../llvm -G Ninja -DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-gnu 
-DLLVM_USE_LINKER=lld -DLLVM_ENABLE_RUNTIMES="compiler-rt;libunwind" 
-DLLVM_ENABLE_PROJECTS="mlir;clang;clang-tools-extra;lld" 
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ 
-DCMAKE_BUILD_TYPE=RelWithDebInfo
```

Note, in `-DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-gnu`,  there is no 
`unknown` aka vendor section.


With this configure, `libclang_rt.builtin.a` is present in 
```
./lib/clang/19/lib/aarch64-linux-gnu/
```

While clang expects it in
   ```
./lib/clang/19/lib/aarch64-unknown-linux-gnu/    Note "unknown"
```

The reason is that in `computeTargetTriple`, the line
```
llvm::Triple Target(llvm::Triple::normalize(TargetTriple));
```
convert the triple to normalize.

https://github.com/llvm/llvm-project/pull/88334
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)

2024-04-10 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

@aeubanks The problem is that in your configure, the libclang_rt is please in 
`/lib/clang/19/lib/linux/libclang_rt.builtins-arm-android.a`, instead 
of
`/lib/clang/19/lib/arm-unknown-linux-android/libclang_rt.builtins.a`.

https://github.com/llvm/llvm-project/pull/87866
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)

2024-04-10 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa converted_to_draft 
https://github.com/llvm/llvm-project/pull/88334
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Look for compiler-rt from subdir given by --target (PR #88334)

2024-04-10 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/88334

Currently, clang looks for compiler-rt only from the normalized triple subdir. 
While if we are configured with a non-normalized triple with 
-DLLVM_DEFAULT_TARGET_TRIPLE, such as triples without vendor section, clang 
will fail to find compiler_rt.

Let's look for compiler_rt from the subdir with name from --target option, too.

To archive this, we add a new member called Origin to class Triple.

Fixes: #87150.

>From a4d6590cf3cecf90b3914933313749e8aad03210 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Mon, 1 Apr 2024 17:17:08 +0800
Subject: [PATCH] Look for compiler-rt from subdir given by --target

Currently, clang looks for compiler-rt only from the normalized
triple subdir. While if we are configured with a non-normalized
triple with -DLLVM_DEFAULT_TARGET_TRIPLE, such as triples without
vendor section, clang will fail to find compiler_rt.

Let's look for compiler_rt from the subdir with name from --target
option.

To archive this, we add a new member called Origin to class Triple.

Fixes: #87150.
---
 clang/lib/Driver/Driver.cpp | 1 +
 clang/lib/Driver/ToolChain.cpp  | 6 ++
 llvm/include/llvm/TargetParser/Triple.h | 6 ++
 llvm/lib/TargetParser/Triple.cpp| 6 +++---
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e7335a61b10c53..4a0c939039eb31 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -516,6 +516,7 @@ static llvm::Triple computeTargetTriple(const Driver ,
 TargetTriple = A->getValue();
 
   llvm::Triple Target(llvm::Triple::normalize(TargetTriple));
+  Target.setOrigin(TargetTriple);
 
   // GNU/Hurd's triples should have been -hurd-gnu*, but were historically made
   // -gnu* only, and we can not change this, so we have to detect that case as
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 237092ed07e5dc..57f27a61c4060b 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -755,6 +755,12 @@ std::optional
 ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   auto getPathForTriple =
   [&](const llvm::Triple ) -> std::optional {
+if (!Triple.getOrigin().empty()) {
+  SmallString<128> Po(BaseDir);
+  llvm::sys::path::append(Po, Triple.getOrigin());
+  if (getVFS().exists(Po))
+return std::string(Po);
+}
 SmallString<128> P(BaseDir);
 llvm::sys::path::append(P, Triple.str());
 if (getVFS().exists(P))
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index f256e2b205a889..a2fc28ada0ca31 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -298,6 +298,8 @@ class Triple {
 private:
   std::string Data;
 
+  StringRef Origin = StringRef();
+
   /// The parsed arch type.
   ArchType Arch{};
 
@@ -425,6 +427,8 @@ class Triple {
 
   const std::string () const { return Data; }
 
+  const StringRef getOrigin() const { return Origin; }
+
   /// Get the architecture (first) component of the triple.
   StringRef getArchName() const;
 
@@ -1058,6 +1062,8 @@ class Triple {
   /// @name Mutators
   /// @{
 
+  void setOrigin(StringRef Orig) { Origin = Orig; };
+
   /// Set the architecture (first) component of the triple to a known type.
   void setArch(ArchType Kind, SubArchType SubArch = NoSubArch);
 
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 624679ff507a7f..ce44903d0f7d70 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -928,9 +928,9 @@ static Triple::ObjectFormatType getDefaultFormat(const 
Triple ) {
 /// This stores the string representation and parses the various pieces into
 /// enum members.
 Triple::Triple(const Twine )
-: Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
-  Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
-  ObjectFormat(UnknownObjectFormat) {
+: Data(Str.str()), Origin(Str.getSingleStringRef()), Arch(UnknownArch),
+  SubArch(NoSubArch), Vendor(UnknownVendor), OS(UnknownOS),
+  Environment(UnknownEnvironment), ObjectFormat(UnknownObjectFormat) {
   // Do minimal parsing by hand here.
   SmallVector Components;
   StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)

2024-04-10 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

For me, I think that it is a good idea to always warn/hint the full/normalized 
path.
For compatible reason, we can still try to find libraries in old-style or 
non-full/normalized paths, while should not hint them.

https://github.com/llvm/llvm-project/pull/87866
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Clang: Return new layout path if cannot find CRT (PR #87319)

2024-04-08 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

Replaced by: https://github.com/llvm/llvm-project/issues/87150

https://github.com/llvm/llvm-project/pull/87319
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Clang: Return new layout path if cannot find CRT (PR #87319)

2024-04-08 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa closed 
https://github.com/llvm/llvm-project/pull/87319
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty (PR #87866)

2024-04-08 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa approved this pull request.


https://github.com/llvm/llvm-project/pull/87866
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Clang: Return new layout path if cannot find CRT (PR #87319)

2024-04-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/87319
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Clang: Return new layout path if cannot find CRT (PR #87319)

2024-04-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/87319

In ToolChain::getCompilerRT:
  If none is found, use a file name from the new layout, which may get
  printed in an error message, aiding users in knowing what Clang is
  looking for.

But in current code, the old layout is printed if no libclang_rt.builtin is 
found with cmd like:
  ./bin/clang --target=aarch64-linux-gnu -rtlib=compiler-rt hello.c

aarch64-linux-gnu/bin/ld: cannot find 
/lib/clang/19/lib/linux/libclang_rt.builtins-aarch64.a: No such file or 
directory

>From 2c8132f08eedfe522ca4dcdcc5bbb11ffb629dd2 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 2 Apr 2024 15:50:23 +0800
Subject: [PATCH] Clang: Return new layout path if cannot find CRT

In ToolChain::getCompilerRT:
  // If none is found, use a file name from the new layout, which may get
  // printed in an error message, aiding users in knowing what Clang is
  // looking for.

But in current code, the old layout is printed if no
libclang_rt.builtin is found with cmd like:
  ./bin/clang --target=aarch64-linux-gnu -rtlib=compiler-rt hello.c
---
 clang/lib/Driver/ToolChain.cpp | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 03450fc0f57b93..3b5960992a9dd1 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -692,12 +692,21 @@ std::string ToolChain::getCompilerRT(const ArgList , 
StringRef Component,
   buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/true);
   SmallString<128> OldPath(getCompilerRTPath());
   llvm::sys::path::append(OldPath, CRTBasename);
-  if (Path.empty() || getVFS().exists(OldPath))
+  if (getVFS().exists(OldPath))
 return std::string(OldPath);
 
   // If none is found, use a file name from the new layout, which may get
   // printed in an error message, aiding users in knowing what Clang is
   // looking for.
+  if (Path.empty()) {
+CRTBasename =
+buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
+SmallString<128> NewP(D.ResourceDir);
+llvm::sys::path::append(NewP, "lib");
+llvm::sys::path::append(NewP, getTriple().str());
+llvm::sys::path::append(NewP, CRTBasename);
+return std::string(NewP);
+  }
   return std::string(Path);
 }
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] MIPS/Clang: Set HasUnalignedAccess false if +strict-align (PR #87257)

2024-04-01 Thread YunQiang Su via cfe-commits


@@ -330,6 +331,8 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 IsMicromips = true;
   else if (Feature == "+mips32r6" || Feature == "+mips64r6")
 HasUnalignedAccess = true;
+  else if (Feature == "+strict-align")
+StrictAlign = true;

wzssyqa wrote:

We cannot due to that +strict-align may be listed before +mips32/64.

I have some try. In all my try, +mips32/64 appeared before +strict-align.
But I am not sure that +mips32/64 will always appear before +strict-align.

https://github.com/llvm/llvm-project/pull/87257
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] MIPS/Clang: Set HasUnalignedAccess false if +strict-align (PR #87257)

2024-04-01 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/87257

TargetInfo has HasUnalignedAccess support now. For MIPSr6, we should set it 
according strict-align.

For pre-R6, we always set strict-align and HasUnalignedAccess to false.

>From ecee40e72582c98e74e89d3aff97a832ece3fd70 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 2 Apr 2024 00:20:55 +0800
Subject: [PATCH] MIPS/Clang: Set HasUnalignedAccess false if +strict-align

TargetInfo has HasUnalignedAccess support now. For MIPSr6,
we should set it according strict-align.

For pre-R6, we always set strict-align and HasUnalignedAccess to
false.
---
 clang/lib/Basic/Targets/Mips.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index c9dcf434c93b0b..f5ce1bc735a700 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -318,6 +318,7 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 FPMode = isFP64Default() ? FP64 : FPXX;
 NoOddSpreg = false;
 bool OddSpregGiven = false;
+bool StrictAlign = false;
 
 for (const auto  : Features) {
   if (Feature == "+single-float")
@@ -330,6 +331,8 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 IsMicromips = true;
   else if (Feature == "+mips32r6" || Feature == "+mips64r6")
 HasUnalignedAccess = true;
+  else if (Feature == "+strict-align")
+StrictAlign = true;
   else if (Feature == "+dsp")
 DspRev = std::max(DspRev, DSP1);
   else if (Feature == "+dspr2")
@@ -368,6 +371,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 if (FPMode == FPXX && !OddSpregGiven)
   NoOddSpreg = true;
 
+if (StrictAlign)
+  HasUnalignedAccess = false;
+
 setDataLayout();
 
 return true;

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] MIPS/Clang: Set HasUnalignedAccess false if +strict-align (PR #87256)

2024-04-01 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/87256

TargetInfo has HasUnalignedAccess support now. For MIPSr6, we should set it 
according strict-align.

For pre-R6, we always set strict-align and HasUnalignedAccess to false.

>From ecee40e72582c98e74e89d3aff97a832ece3fd70 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 2 Apr 2024 00:20:55 +0800
Subject: [PATCH] MIPS/Clang: Set HasUnalignedAccess false if +strict-align

TargetInfo has HasUnalignedAccess support now. For MIPSr6,
we should set it according strict-align.

For pre-R6, we always set strict-align and HasUnalignedAccess to
false.
---
 clang/lib/Basic/Targets/Mips.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index c9dcf434c93b0b..f5ce1bc735a700 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -318,6 +318,7 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 FPMode = isFP64Default() ? FP64 : FPXX;
 NoOddSpreg = false;
 bool OddSpregGiven = false;
+bool StrictAlign = false;
 
 for (const auto  : Features) {
   if (Feature == "+single-float")
@@ -330,6 +331,8 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 IsMicromips = true;
   else if (Feature == "+mips32r6" || Feature == "+mips64r6")
 HasUnalignedAccess = true;
+  else if (Feature == "+strict-align")
+StrictAlign = true;
   else if (Feature == "+dsp")
 DspRev = std::max(DspRev, DSP1);
   else if (Feature == "+dspr2")
@@ -368,6 +371,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 if (FPMode == FPXX && !OddSpregGiven)
   NoOddSpreg = true;
 
+if (StrictAlign)
+  HasUnalignedAccess = false;
+
 setDataLayout();
 
 return true;

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] MIPS: Support -m(no-)unaligned-access for r6 (PR #85174)

2024-03-20 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa closed 
https://github.com/llvm/llvm-project/pull/85174
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] MIPS: Support -m(no-)unaligned-access for r6 (PR #85174)

2024-03-16 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/85174

>From 7e1cf74f4fc9271e88b62462ea9a38826fd3ee38 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Thu, 14 Mar 2024 11:48:36 +0800
Subject: [PATCH] MIPS: Support -m(no-)strict-align for r6

MIPSr6 ISA requires normal load/store instructions support
misunaligned memory access, while it is not always do so
by hardware. On some microarchitectures or some corner cases
it may need support by OS.

Don't confuse with pre-R6's lwl/lwr famlily: MIPSr6 doesn't
support them, instead, r6 requires lw instruction support
misunaligned memory access. So, if -mstrict-align is used for
pre-R6, lwl/lwr won't be disabled.

If -mstrict-align is used for r6 and the access is not well
aligned, some lb/lh instructions will be used to replace lw.
This is useful for OS kernels.

To be back-compatible with GCC, -m(no-)unaligned-access are also
added as Neg-Alias of -m(no-)strict-align.
---
 clang/include/clang/Driver/Options.td |  4 +-
 clang/lib/Driver/ToolChains/Arch/Mips.cpp |  9 +++
 clang/test/Driver/mips-features.c | 26 +++
 llvm/lib/Target/Mips/Mips.td  |  4 ++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 16 -
 llvm/lib/Target/Mips/MipsSEISelLowering.cpp   | 11 ++-
 llvm/lib/Target/Mips/MipsSubtarget.cpp|  2 +-
 llvm/lib/Target/Mips/MipsSubtarget.h  |  7 +-
 llvm/test/CodeGen/Mips/msa/f16-llvm-ir.ll | 10 +--
 .../CodeGen/Mips/no-unaligned-access-r6.ll| 69 +++
 10 files changed, 145 insertions(+), 13 deletions(-)
 create mode 100644 llvm/test/CodeGen/Mips/no-unaligned-access-r6.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index acb7592e98100a..6567e7a7a9a745 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4704,9 +4704,9 @@ def mrvv_vector_bits_EQ : Joined<["-"], 
"mrvv-vector-bits=">, Group,
 " (RISC-V only)")>;
 
 def munaligned_access : Flag<["-"], "munaligned-access">, Group,
-  HelpText<"Allow memory accesses to be unaligned (AArch32 only)">;
+  HelpText<"Allow memory accesses to be unaligned (AArch32/MIPSr6 only)">;
 def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group,
-  HelpText<"Force all memory accesses to be aligned (AArch32 only)">;
+  HelpText<"Force all memory accesses to be aligned (AArch32/MIPSr6 only)">;
 def munaligned_symbols : Flag<["-"], "munaligned-symbols">, Group,
   HelpText<"Expect external char-aligned symbols to be without ABI alignment 
(SystemZ only)">;
 def mno_unaligned_symbols : Flag<["-"], "mno-unaligned-symbols">, 
Group,
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp 
b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index fe9d112b8800b1..74a8874a3ea2b7 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -341,6 +341,15 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
"dspr2");
   AddTargetFeature(Args, Features, options::OPT_mmsa, options::OPT_mno_msa,
"msa");
+  if (Arg *A = Args.getLastArg(
+  options::OPT_mstrict_align, options::OPT_mno_strict_align,
+  options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
+if (A->getOption().matches(options::OPT_mstrict_align) ||
+A->getOption().matches(options::OPT_mno_unaligned_access))
+  Features.push_back(Args.MakeArgString("+strict-align"));
+else
+  Features.push_back(Args.MakeArgString("-strict-align"));
+  }
 
   // Add the last -mfp32/-mfpxx/-mfp64, if none are given and the ABI is O32
   // pass -mfpxx, or if none are given and fp64a is default, pass fp64 and
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fd06b1400c3123..5e92dccaa02abb 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -462,3 +462,29 @@
 // RUN: -mrelax-pic-calls -mno-relax-pic-calls 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-RELAX-PIC-CALLS %s
 // CHECK-NO-RELAX-PIC-CALLS: "-mllvm" "-mips-jalr-reloc=0"
+//
+// -mno-unaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -munaligned-access -mno-strict-align \
+// RUN: -mno-unaligned-access 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-STRICT-ALIGN %s
+// CHECK-STRICT-ALIGN: "-target-feature" "+strict-align"
+//
+// -munaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-unaligned-access -mstrict-align \
+// RUN: -munaligned-access 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-STRICT-ALIGN %s
+// CHECK-NO-STRICT-ALIGN: "-target-feature" "-strict-align"
+//
+// -mstrict-align
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -munaligned-access -mno-strict-align \
+// RUN: -mstrict-align 2>&1 \
+// RUN:   | FileCheck 

[clang] [llvm] MIPS: Support -m(no-)unaligned-access for r6 (PR #85174)

2024-03-16 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/85174
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] MIPS: Support -m(no-)unaligned-access for r6 (PR #85174)

2024-03-16 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/85174

>From e75523f5ab1bb58a495afdd30203a0c7c93c7ec4 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Thu, 14 Mar 2024 11:48:36 +0800
Subject: [PATCH] MIPS: Support -m(no-)strict-align for r6

MIPSr6 ISA requires normal load/store instructions support
misunaligned memory access, while it is not always do so
by hardware. On some microarchitectures or some corner cases
it may need support by OS.

Don't confuse with pre-R6's lwl/lwr famlily: MIPSr6 doesn't
support them, instead, r6 requires lw instruction support
misunaligned memory access. So, if -mstrict-align is used for
pre-R6, lwl/lwr won't be disabled.

If -mstrict-align is used for r6 and the access is not well
aligned, some lb/lh instructions will be used to replace lw.
This is useful for OS kernels.

To be back-compatible with GCC, -m(no-)unaligned-access are also
added as Neg-Alias of -m(no-)strict-align.
---
 clang/include/clang/Driver/Options.td |  4 +-
 clang/lib/Driver/ToolChains/Arch/Mips.cpp | 13 
 clang/test/Driver/mips-features.c | 26 +++
 llvm/lib/Target/Mips/Mips.td  |  4 ++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 16 -
 llvm/lib/Target/Mips/MipsSEISelLowering.cpp   | 11 ++-
 llvm/lib/Target/Mips/MipsSubtarget.cpp|  2 +-
 llvm/lib/Target/Mips/MipsSubtarget.h  |  7 +-
 llvm/test/CodeGen/Mips/msa/f16-llvm-ir.ll | 10 +--
 .../CodeGen/Mips/no-unaligned-access-r6.ll| 69 +++
 10 files changed, 149 insertions(+), 13 deletions(-)
 create mode 100644 llvm/test/CodeGen/Mips/no-unaligned-access-r6.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index acb7592e98100a..6567e7a7a9a745 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4704,9 +4704,9 @@ def mrvv_vector_bits_EQ : Joined<["-"], 
"mrvv-vector-bits=">, Group,
 " (RISC-V only)")>;
 
 def munaligned_access : Flag<["-"], "munaligned-access">, Group,
-  HelpText<"Allow memory accesses to be unaligned (AArch32 only)">;
+  HelpText<"Allow memory accesses to be unaligned (AArch32/MIPSr6 only)">;
 def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group,
-  HelpText<"Force all memory accesses to be aligned (AArch32 only)">;
+  HelpText<"Force all memory accesses to be aligned (AArch32/MIPSr6 only)">;
 def munaligned_symbols : Flag<["-"], "munaligned-symbols">, Group,
   HelpText<"Expect external char-aligned symbols to be without ABI alignment 
(SystemZ only)">;
 def mno_unaligned_symbols : Flag<["-"], "mno-unaligned-symbols">, 
Group,
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp 
b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index fe9d112b8800b1..b6c8a897106f20 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -341,6 +341,19 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
"dspr2");
   AddTargetFeature(Args, Features, options::OPT_mmsa, options::OPT_mno_msa,
"msa");
+  AddTargetFeature(Args, Features, options::OPT_mstrict_align,
+   options::OPT_mno_strict_align, "strict-align");
+  AddTargetFeature(Args, Features, options::OPT_mno_unaligned_access,
+   options::OPT_munaligned_access, "strict-align");
+  if (Arg *A = Args.getLastArg(
+  options::OPT_mstrict_align, options::OPT_mno_strict_align,
+  options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
+if (A->getOption().matches(options::OPT_mstrict_align) ||
+A->getOption().matches(options::OPT_mno_unaligned_access))
+  Features.push_back(Args.MakeArgString("+strict-align"));
+else
+  Features.push_back(Args.MakeArgString("-strict-align"));
+  }
 
   // Add the last -mfp32/-mfpxx/-mfp64, if none are given and the ABI is O32
   // pass -mfpxx, or if none are given and fp64a is default, pass fp64 and
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fd06b1400c3123..5e92dccaa02abb 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -462,3 +462,29 @@
 // RUN: -mrelax-pic-calls -mno-relax-pic-calls 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-RELAX-PIC-CALLS %s
 // CHECK-NO-RELAX-PIC-CALLS: "-mllvm" "-mips-jalr-reloc=0"
+//
+// -mno-unaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -munaligned-access -mno-strict-align \
+// RUN: -mno-unaligned-access 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-STRICT-ALIGN %s
+// CHECK-STRICT-ALIGN: "-target-feature" "+strict-align"
+//
+// -munaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-unaligned-access -mstrict-align \
+// RUN: -munaligned-access 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-STRICT-ALIGN %s
+// 

[clang] [Driver] Don't alias -mstrict-align to -mno-unaligned-access (PR #85350)

2024-03-14 Thread YunQiang Su via cfe-commits


@@ -321,9 +321,11 @@ void aarch64::getAArch64TargetFeatures(const Driver ,
 }
   }
 
-  if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
-   options::OPT_munaligned_access)) {
-if (A->getOption().matches(options::OPT_mno_unaligned_access))
+  if (Arg *A = Args.getLastArg(
+  options::OPT_mstrict_align, options::OPT_mno_strict_align,
+  options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
+if (A->getOption().matches(options::OPT_mstrict_align) ||
+A->getOption().matches(options::OPT_mno_unaligned_access))

wzssyqa wrote:

LGTM.

I will add `strict_align` for MIPSr6 to GCC, and rebase my PR to LLVM.

https://github.com/llvm/llvm-project/pull/85350
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Don't alias -mstrict-align to -mno-unaligned-access (PR #85350)

2024-03-14 Thread YunQiang Su via cfe-commits


@@ -321,9 +321,11 @@ void aarch64::getAArch64TargetFeatures(const Driver ,
 }
   }
 
-  if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
-   options::OPT_munaligned_access)) {
-if (A->getOption().matches(options::OPT_mno_unaligned_access))
+  if (Arg *A = Args.getLastArg(
+  options::OPT_mstrict_align, options::OPT_mno_strict_align,
+  options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
+if (A->getOption().matches(options::OPT_mstrict_align) ||
+A->getOption().matches(options::OPT_mno_unaligned_access))

wzssyqa wrote:

Why keep `mno_unaligned_access` for AArch64 while remove it from RISC-V and 
LoongArch?

In fact `mno_unaligned_access` is not supported by GCC for  AArch64?

https://github.com/llvm/llvm-project/pull/85350
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Better bitfield access units (PR #65742)

2024-03-14 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

> For MIPSr6, it is just like AARCH64, since some microarchitecture doesn't 
> support mis-unaligned well in hardware level, so we need an options to 
> disable it: kernel may need it.
> 
> For GCC, we have `-mno-unalgined-access`. We need also add this option to 
> clang.

https://github.com/llvm/llvm-project/pull/85174
Add -m(no-)unaligned-access for MIPSr6.

https://github.com/llvm/llvm-project/pull/65742
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] MIPS: Support -m(no-)unaligned-access for r6 (PR #85174)

2024-03-13 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/85174

MIPSr6 ISA requires normal load/store instructions support misunaligned memory 
access, while it is not always do so by hardware. On some microarchitectures or 
some corner cases it may need support by OS.

Don't confuse with pre-R6's lwl/lwr famlily: MIPSr6 doesn't support them, 
instead, r6 requires lw instruction support misunaligned memory access. So, if 
-mno-unaligned-access is used for pre-R6, lwl/lwr won't be disabled.

If -mno-unaligned-access is used for r6 and the access is not well aligned, 
some lb/lh instructions will be used to replace lw. This is useful for OS 
kernels.

>From a74a9bbd2ff2c6589db4c9756cf809c22e98fa64 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Thu, 14 Mar 2024 11:48:36 +0800
Subject: [PATCH] MIPS: Support -m(no-)unaligned-access for r6

MIPSr6 ISA requires normal load/store instructions support
misunaligned memory access, while it is not always do so
by hardware. On some microarchitectures or some corner cases
it may need support by OS.

Don't confuse with pre-R6's lwl/lwr famlily: MIPSr6 doesn't
support them, instead, r6 requires lw instruction support
misunaligned memory access. So, if -mno-unaligned-access is
used for pre-R6, lwl/lwr won't be disabled.

If -mno-unaligned-access is used for r6 and the access is
not well aligned, some lb/lh instructions will be used to replace
lw. This is useful for OS kernels.
---
 clang/include/clang/Driver/Options.td |  4 +-
 clang/lib/Driver/ToolChains/Arch/Mips.cpp |  2 +
 clang/test/Driver/mips-features.c | 26 +++
 llvm/lib/Target/Mips/Mips.td  |  4 ++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 16 -
 llvm/lib/Target/Mips/MipsSEISelLowering.cpp   | 11 ++-
 llvm/lib/Target/Mips/MipsSubtarget.cpp|  1 +
 llvm/lib/Target/Mips/MipsSubtarget.h  |  7 +-
 llvm/test/CodeGen/Mips/msa/f16-llvm-ir.ll | 10 +--
 .../CodeGen/Mips/no-unaligned-access-r6.ll| 69 +++
 10 files changed, 138 insertions(+), 12 deletions(-)
 create mode 100644 llvm/test/CodeGen/Mips/no-unaligned-access-r6.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1fac7b6f0093d8..6d3645f0a66828 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4696,9 +4696,9 @@ def mrvv_vector_bits_EQ : Joined<["-"], 
"mrvv-vector-bits=">, Group,
 " (RISC-V only)")>;
 
 def munaligned_access : Flag<["-"], "munaligned-access">, Group,
-  HelpText<"Allow memory accesses to be unaligned 
(AArch32/AArch64/LoongArch/RISC-V only)">;
+  HelpText<"Allow memory accesses to be unaligned 
(AArch32/AArch64/LoongArch/MIPS/RISC-V only)">;
 def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group,
-  HelpText<"Force all memory accesses to be aligned 
(AArch32/AArch64/LoongArch/RISC-V only)">;
+  HelpText<"Force all memory accesses to be aligned 
(AArch32/AArch64/LoongArch/MIPS/RISC-V only)">;
 def munaligned_symbols : Flag<["-"], "munaligned-symbols">, Group,
   HelpText<"Expect external char-aligned symbols to be without ABI alignment 
(SystemZ only)">;
 def mno_unaligned_symbols : Flag<["-"], "mno-unaligned-symbols">, 
Group,
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp 
b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index fe9d112b8800b1..1de11811dccbc1 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -341,6 +341,8 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
"dspr2");
   AddTargetFeature(Args, Features, options::OPT_mmsa, options::OPT_mno_msa,
"msa");
+  AddTargetFeature(Args, Features, options::OPT_mno_unaligned_access,
+   options::OPT_munaligned_access, "no-unaligned-access");
 
   // Add the last -mfp32/-mfpxx/-mfp64, if none are given and the ABI is O32
   // pass -mfpxx, or if none are given and fp64a is default, pass fp64 and
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fd06b1400c3123..9e724b34e869d4 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -462,3 +462,29 @@
 // RUN: -mrelax-pic-calls -mno-relax-pic-calls 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-RELAX-PIC-CALLS %s
 // CHECK-NO-RELAX-PIC-CALLS: "-mllvm" "-mips-jalr-reloc=0"
+//
+// -mno-unaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -munaligned-access -mno-strict-align \
+// RUN: -mno-unaligned-access 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+// CHECK-NO-UNALIGNED-ACCESS: "-target-feature" "+no-unaligned-access"
+//
+// -munaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-unaligned-access -mstrict-align \
+// RUN: -munaligned-access 2>&1 \
+// RUN:   | FileCheck 

[clang] [clang] Better bitfield access units (PR #65742)

2024-02-21 Thread YunQiang Su via cfe-commits


@@ -132,6 +132,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
   : LoongArchTargetInfo(Triple, Opts) {
 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
 IntMaxType = Int64Type = SignedLong;
+HasCheapUnalignedBitfieldAccess = true;

wzssyqa wrote:

> > Only set it to true when -mno-unaligned-access.
> 
> In `LoongArchTargetInfo::handleTargetFeatures()`, we can handle the feature 
> `-ual`.

Maybe it's true, while you may need it if you need to build a generic kernel 
image for both microarchitectures.

https://github.com/llvm/llvm-project/pull/65742
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Better bitfield access units (PR #65742)

2024-02-21 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/65742
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Better bitfield access units (PR #65742)

2024-02-21 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/65742
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Better bitfield access units (PR #65742)

2024-02-21 Thread YunQiang Su via cfe-commits


@@ -132,6 +132,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
   : LoongArchTargetInfo(Triple, Opts) {
 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
 IntMaxType = Int64Type = SignedLong;
+HasCheapUnalignedBitfieldAccess = true;

wzssyqa wrote:

Same to MIPS, while there is no -mno-unaligned-access for MIPS yet. I will add 
it support.

https://github.com/llvm/llvm-project/pull/65742
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Better bitfield access units (PR #65742)

2024-02-21 Thread YunQiang Su via cfe-commits


@@ -132,6 +132,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
   : LoongArchTargetInfo(Triple, Opts) {
 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
 IntMaxType = Int64Type = SignedLong;
+HasCheapUnalignedBitfieldAccess = true;

wzssyqa wrote:

Only set it to true when -mno-unaligned-access.

https://github.com/llvm/llvm-project/pull/65742
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-21 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/79116

>From 0da681135e785b01d67b0cef02581e0bba028ef3 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Jan 2024 18:14:48 +0800
Subject: [PATCH] MIPS/clang: Fix asm constraint for softfloat

This include 2 fixes:
1. Disallow 'f' for softfloat.
2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: #64241
---
 clang/lib/Basic/Targets/Mips.h|  3 +++
 .../CodeGen/Mips/inline-asm-constraints.c | 18 +
 clang/test/Sema/inline-asm-validate-mips.c|  8 ++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 10 +---
 .../Mips/inlineasm-constraints-softfloat.ll   | 25 +++
 5 files changed, 61 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/Mips/inline-asm-constraints.c
 create mode 100644 clang/test/Sema/inline-asm-validate-mips.c
 create mode 100644 llvm/test/CodeGen/Mips/inlineasm-constraints-softfloat.ll

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f46b95abfd75c7..2b8ad6645e605f 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 case 'd': // Equivalent to "r" unless generating MIPS16 code.
 case 'y': // Equivalent to "r", backward compatibility only.
 case 'f': // floating-point registers.
+  if (*Name == 'f' && FloatABI == SoftFloat)
+return false;
+  LLVM_FALLTHROUGH;
 case 'c': // $25 for indirect jumps
 case 'l': // lo register
 case 'x': // hilo register pair
diff --git a/clang/test/CodeGen/Mips/inline-asm-constraints.c 
b/clang/test/CodeGen/Mips/inline-asm-constraints.c
new file mode 100644
index 00..0a4cb0b34570e6
--- /dev/null
+++ b/clang/test/CodeGen/Mips/inline-asm-constraints.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -triple mips -target-feature +soft-float \
+// RUN:-DSOFT_FLOAT_CONSTRAINT_R \
+// RUN:-DFLOAT=float -emit-llvm -o - \
+// RUN:  | FileCheck %s --check-prefix SOFT_FLOAT_CONSTRAINT_R_SINGLE
+
+// RUN: %clang_cc1 %s -triple mips -target-feature +soft-float \
+// RUN:-DSOFT_FLOAT_CONSTRAINT_R \
+// RUN:-DFLOAT=double -emit-llvm -o - \
+// RUN:  | FileCheck %s --check-prefix SOFT_FLOAT_CONSTRAINT_R_DOUBLE
+
+#ifdef SOFT_FLOAT_CONSTRAINT_R
+// SOFT_FLOAT_CONSTRAINT_R_SINGLE: call void asm sideeffect "", 
"r,~{$1}"(float %2) #1, !srcloc !2
+// SOFT_FLOAT_CONSTRAINT_R_DOUBLE: call void asm sideeffect "", 
"r,~{$1}"(double %2) #1, !srcloc !2
+void read_float(FLOAT* p) {
+FLOAT result = *p;
+__asm__("" ::"r"(result));
+}
+#endif // SOFT_FLOAT_CONSTRAINT_R
diff --git a/clang/test/Sema/inline-asm-validate-mips.c 
b/clang/test/Sema/inline-asm-validate-mips.c
new file mode 100644
index 00..5a123cc5fa79c3
--- /dev/null
+++ b/clang/test/Sema/inline-asm-validate-mips.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple mips -target-feature +soft-float 
-DSOFT_FLOAT_NO_CONSTRAINT_F -fsyntax-only -verify %s
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float p) {
+float result = p;
+__asm__("" ::"f"(result)); // expected-error{{invalid input constraint 'f' 
in asm}}
+}
+#endif // SOFT_FLOAT_NO_CONSTRAINT_F
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index b2812f87914df7..97e830cec27cad 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -4128,14 +4128,18 @@ MipsTargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'd': // Address register. Same as 'r' unless generating MIPS16 code.
 case 'y': // Same as 'r'. Exists for compatibility.
 case 'r':
-  if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 || VT == MVT::i1) {
+  if ((VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 ||
+   VT == MVT::i1) ||
+  (VT == MVT::f32 && Subtarget.useSoftFloat())) {
 if (Subtarget.inMips16Mode())
   return std::make_pair(0U, ::CPU16RegsRegClass);
 return std::make_pair(0U, ::GPR32RegClass);
   }
-  if (VT == MVT::i64 && !Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  !Subtarget.isGP64bit())
 return std::make_pair(0U, ::GPR32RegClass);
-  if (VT == MVT::i64 && Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  Subtarget.isGP64bit())
 return std::make_pair(0U, ::GPR64RegClass);
   // This will generate an error message
   return std::make_pair(0U, nullptr);
diff --git a/llvm/test/CodeGen/Mips/inlineasm-constraints-softfloat.ll 

[clang] [clang] Better bitfield access units (PR #65742)

2024-02-21 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

> `-mno-unalgined-access` has been added since clang17: 
> https://reviews.llvm.org/D149946

This option is for LoongArch instead of MIPSr6.

https://github.com/llvm/llvm-project/pull/65742
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Better bitfield access units (PR #65742)

2024-02-21 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

For MIPSr6, it is just like AARCH64, since some microarchitecture doesn't 
support mis-unaligned well in hardware level, so we need an options to disable 
it: kernel may need it.

For GCC, we have `-mno-unalgined-access`. We need also add this option to clang.

https://github.com/llvm/llvm-project/pull/65742
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-21 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/79116

>From 838394878054831066e563fa243665ba6d68d824 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Jan 2024 18:14:48 +0800
Subject: [PATCH] MIPS/clang: Fix asm constraint for softfloat

This include 2 fixes:
1. Disallow 'f' for softfloat.
2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: #64241
---
 clang/lib/Basic/Targets/Mips.h|  3 +++
 .../CodeGen/Mips/inline-asm-constraints.c | 18 +
 clang/test/Sema/inline-asm-validate-mips.c|  8 ++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 10 +---
 .../Mips/inlineasm-constraints-softfloat.ll   | 25 +++
 5 files changed, 61 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/Mips/inline-asm-constraints.c
 create mode 100644 clang/test/Sema/inline-asm-validate-mips.c
 create mode 100644 llvm/test/CodeGen/Mips/inlineasm-constraints-softfloat.ll

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f46b95abfd75c7..2b8ad6645e605f 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 case 'd': // Equivalent to "r" unless generating MIPS16 code.
 case 'y': // Equivalent to "r", backward compatibility only.
 case 'f': // floating-point registers.
+  if (*Name == 'f' && FloatABI == SoftFloat)
+return false;
+  LLVM_FALLTHROUGH;
 case 'c': // $25 for indirect jumps
 case 'l': // lo register
 case 'x': // hilo register pair
diff --git a/clang/test/CodeGen/Mips/inline-asm-constraints.c 
b/clang/test/CodeGen/Mips/inline-asm-constraints.c
new file mode 100644
index 00..0a4cb0b34570e6
--- /dev/null
+++ b/clang/test/CodeGen/Mips/inline-asm-constraints.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -triple mips -target-feature +soft-float \
+// RUN:-DSOFT_FLOAT_CONSTRAINT_R \
+// RUN:-DFLOAT=float -emit-llvm -o - \
+// RUN:  | FileCheck %s --check-prefix SOFT_FLOAT_CONSTRAINT_R_SINGLE
+
+// RUN: %clang_cc1 %s -triple mips -target-feature +soft-float \
+// RUN:-DSOFT_FLOAT_CONSTRAINT_R \
+// RUN:-DFLOAT=double -emit-llvm -o - \
+// RUN:  | FileCheck %s --check-prefix SOFT_FLOAT_CONSTRAINT_R_DOUBLE
+
+#ifdef SOFT_FLOAT_CONSTRAINT_R
+// SOFT_FLOAT_CONSTRAINT_R_SINGLE: call void asm sideeffect "", 
"r,~{$1}"(float %2) #1, !srcloc !2
+// SOFT_FLOAT_CONSTRAINT_R_DOUBLE: call void asm sideeffect "", 
"r,~{$1}"(double %2) #1, !srcloc !2
+void read_float(FLOAT* p) {
+FLOAT result = *p;
+__asm__("" ::"r"(result));
+}
+#endif // SOFT_FLOAT_CONSTRAINT_R
diff --git a/clang/test/Sema/inline-asm-validate-mips.c 
b/clang/test/Sema/inline-asm-validate-mips.c
new file mode 100644
index 00..5a123cc5fa79c3
--- /dev/null
+++ b/clang/test/Sema/inline-asm-validate-mips.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple mips -target-feature +soft-float 
-DSOFT_FLOAT_NO_CONSTRAINT_F -fsyntax-only -verify %s
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float p) {
+float result = p;
+__asm__("" ::"f"(result)); // expected-error{{invalid input constraint 'f' 
in asm}}
+}
+#endif // SOFT_FLOAT_NO_CONSTRAINT_F
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index b2812f87914df7..97e830cec27cad 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -4128,14 +4128,18 @@ MipsTargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'd': // Address register. Same as 'r' unless generating MIPS16 code.
 case 'y': // Same as 'r'. Exists for compatibility.
 case 'r':
-  if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 || VT == MVT::i1) {
+  if ((VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 ||
+   VT == MVT::i1) ||
+  (VT == MVT::f32 && Subtarget.useSoftFloat())) {
 if (Subtarget.inMips16Mode())
   return std::make_pair(0U, ::CPU16RegsRegClass);
 return std::make_pair(0U, ::GPR32RegClass);
   }
-  if (VT == MVT::i64 && !Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  !Subtarget.isGP64bit())
 return std::make_pair(0U, ::GPR32RegClass);
-  if (VT == MVT::i64 && Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  Subtarget.isGP64bit())
 return std::make_pair(0U, ::GPR64RegClass);
   // This will generate an error message
   return std::make_pair(0U, nullptr);
diff --git a/llvm/test/CodeGen/Mips/inlineasm-constraints-softfloat.ll 

[clang] [llvm] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-21 Thread YunQiang Su via cfe-commits


@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple mips -target-feature +soft-float 
-DSOFT_FLOAT_NO_CONSTRAINT_F -fsyntax-only -verify %s
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float* p) {

wzssyqa wrote:

Oh, yes. we can use `float p` here.

https://github.com/llvm/llvm-project/pull/79116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-21 Thread YunQiang Su via cfe-commits


@@ -0,0 +1,25 @@
+; RUN: llc  -march=mips < %s | FileCheck %s --check-prefix=MIPS32
+; RUN: llc  -march=mips64 < %s | FileCheck %s --check-prefix=MIPS64
+
+define dso_local void @read_double(double* nocapture noundef readonly %0) 
local_unnamed_addr #0 {

wzssyqa wrote:

Thanks.

https://github.com/llvm/llvm-project/pull/79116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-21 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/79116

>From 0ea3b2be9d364a042c7e7114b0f72fc3c144d2a0 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Jan 2024 18:14:48 +0800
Subject: [PATCH] MIPS/clang: Fix asm constraint for softfloat

This include 2 fixes:
1. Disallow 'f' for softfloat.
2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: #64241
---
 clang/lib/Basic/Targets/Mips.h|  3 +++
 .../CodeGen/Mips/inline-asm-constraints.c | 18 +
 clang/test/Sema/inline-asm-validate-mips.c|  8 ++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 10 +---
 .../Mips/inlineasm-constraints-softfloat.ll   | 25 +++
 5 files changed, 61 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/Mips/inline-asm-constraints.c
 create mode 100644 clang/test/Sema/inline-asm-validate-mips.c
 create mode 100644 llvm/test/CodeGen/Mips/inlineasm-constraints-softfloat.ll

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f46b95abfd75c7..2b8ad6645e605f 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 case 'd': // Equivalent to "r" unless generating MIPS16 code.
 case 'y': // Equivalent to "r", backward compatibility only.
 case 'f': // floating-point registers.
+  if (*Name == 'f' && FloatABI == SoftFloat)
+return false;
+  LLVM_FALLTHROUGH;
 case 'c': // $25 for indirect jumps
 case 'l': // lo register
 case 'x': // hilo register pair
diff --git a/clang/test/CodeGen/Mips/inline-asm-constraints.c 
b/clang/test/CodeGen/Mips/inline-asm-constraints.c
new file mode 100644
index 00..0a4cb0b34570e6
--- /dev/null
+++ b/clang/test/CodeGen/Mips/inline-asm-constraints.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -triple mips -target-feature +soft-float \
+// RUN:-DSOFT_FLOAT_CONSTRAINT_R \
+// RUN:-DFLOAT=float -emit-llvm -o - \
+// RUN:  | FileCheck %s --check-prefix SOFT_FLOAT_CONSTRAINT_R_SINGLE
+
+// RUN: %clang_cc1 %s -triple mips -target-feature +soft-float \
+// RUN:-DSOFT_FLOAT_CONSTRAINT_R \
+// RUN:-DFLOAT=double -emit-llvm -o - \
+// RUN:  | FileCheck %s --check-prefix SOFT_FLOAT_CONSTRAINT_R_DOUBLE
+
+#ifdef SOFT_FLOAT_CONSTRAINT_R
+// SOFT_FLOAT_CONSTRAINT_R_SINGLE: call void asm sideeffect "", 
"r,~{$1}"(float %2) #1, !srcloc !2
+// SOFT_FLOAT_CONSTRAINT_R_DOUBLE: call void asm sideeffect "", 
"r,~{$1}"(double %2) #1, !srcloc !2
+void read_float(FLOAT* p) {
+FLOAT result = *p;
+__asm__("" ::"r"(result));
+}
+#endif // SOFT_FLOAT_CONSTRAINT_R
diff --git a/clang/test/Sema/inline-asm-validate-mips.c 
b/clang/test/Sema/inline-asm-validate-mips.c
new file mode 100644
index 00..5a123cc5fa79c3
--- /dev/null
+++ b/clang/test/Sema/inline-asm-validate-mips.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple mips -target-feature +soft-float 
-DSOFT_FLOAT_NO_CONSTRAINT_F -fsyntax-only -verify %s
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float p) {
+float result = p;
+__asm__("" ::"f"(result)); // expected-error{{invalid input constraint 'f' 
in asm}}
+}
+#endif // SOFT_FLOAT_NO_CONSTRAINT_F
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index b2812f87914df7..97e830cec27cad 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -4128,14 +4128,18 @@ MipsTargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'd': // Address register. Same as 'r' unless generating MIPS16 code.
 case 'y': // Same as 'r'. Exists for compatibility.
 case 'r':
-  if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 || VT == MVT::i1) {
+  if ((VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 ||
+   VT == MVT::i1) ||
+  (VT == MVT::f32 && Subtarget.useSoftFloat())) {
 if (Subtarget.inMips16Mode())
   return std::make_pair(0U, ::CPU16RegsRegClass);
 return std::make_pair(0U, ::GPR32RegClass);
   }
-  if (VT == MVT::i64 && !Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  !Subtarget.isGP64bit())
 return std::make_pair(0U, ::GPR32RegClass);
-  if (VT == MVT::i64 && Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  Subtarget.isGP64bit())
 return std::make_pair(0U, ::GPR64RegClass);
   // This will generate an error message
   return std::make_pair(0U, nullptr);
diff --git a/llvm/test/CodeGen/Mips/inlineasm-constraints-softfloat.ll 

[libunwind] MIPS/libunwind: Use -mfp64 if compiler is FPXX (PR #68521)

2024-02-07 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa closed 
https://github.com/llvm/llvm-project/pull/68521
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] MIPS/libunwind: Use -mfp64 if compiler is FPXX (PR #68521)

2024-02-06 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/68521
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] MIPS/libunwind: Use -mfp64 if compiler is FPXX (PR #68521)

2024-02-06 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

Fangrui Song ***@***.***> 于2024年2月6日周二 13:36写道:

> Libunwind supports FP64 and FP32 modes, but not FPXX. The reason is that,
> FP64 and FP32 have different way to save/restore FPRs. If libunwind is
> built as FPXX, we have no idea which one should we use.
>
> Can you edit the description to name the code that doesn't support FPXX?
>
>
> It's not due to the code bug, but rather the nature of FPXX.
FPXX is an ABI which uses only a common subset of FR=1(FP64) and FR=0
(FP32).
So that FPXX binaries can link with both FP64 and FP32 ones, aka.
FPXX + FP32 -> FP32
FPXX + FP64 -> FP64

While for libunwind, we should save/restore all of FPRs. If we use FPXX,
we can only save/restore a common subset of FPRs, instead of superset.


https://github.com/llvm/llvm-project/pull/68521
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] MIPS/libunwind: Use -mfp64 if compiler is FPXX (PR #68521)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/68521

>From 65db5951e3c30b6c2a112b590839fad6b8ec2944 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Sun, 8 Oct 2023 07:12:45 -0400
Subject: [PATCH] MIPS/libunwind: Use -mfp64 if compiler is FPXX

Libunwind supports FP64 and FP32 modes, but not FPXX.
The reason is that, FP64 and FP32 have different way to save/restore
FPRs. If libunwind is built as FPXX, we have no idea which one should
we use.

If libunwind is built as FP64, it will interoperatable with FPXX/FP64
APPs, and if it is built as FP32, it will interoperatable with
FP32/FPXX. Currently most of O32 APPs are FPXX or FP64, while few are FP32.

So if the compiler is FPXX, which is the default value of most toolchain,
let's switch it to FP64.
---
 libunwind/CMakeLists.txt | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index bb1b052f61d87..806d5a783ec39 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -21,6 +21,7 @@ set(LIBUNWIND_LIBCXX_PATH 
"${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
 "Specify path to libc++ source.")
 
 include(GNUInstallDirs)
+include(CheckSymbolExists)
 
 
#===
 # Setup CMake Options
@@ -96,6 +97,20 @@ endif()
 option(LIBUNWIND_HIDE_SYMBOLS
   "Do not export any symbols from the static library." 
${LIBUNWIND_DEFAULT_HIDE_SYMBOLS})
 
+# If toolchain is FPXX, we switch to FP64 to save the full FPRs. See:
+# 
https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
+check_symbol_exists(__mips_hard_float "" __MIPSHF)
+check_symbol_exists(_ABIO32 "" __MIPS_O32)
+if (__MIPSHF AND __MIPS_O32)
+  file(WRITE 
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
+"#if __mips_fpr != 0\n"
+"# error\n"
+"#endif\n")
+  try_compile(MIPS_FPABI_FPXX ${CMAKE_BINARY_DIR}
+${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
+CMAKE_FLAGS -DCMAKE_C_LINK_EXECUTABLE='echo')
+endif()
+
 
#===
 # Configure System
 
#===
@@ -179,6 +194,10 @@ if (WIN32)
   add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
 endif()
 
+if (MIPS_FPABI_FPXX)
+  add_compile_flags(-mfp64)
+endif()
+
 # Get feature flags.
 # Exceptions
 # Catches C++ exceptions only and tells the compiler to assume that extern C

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/79116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/79116

>From af69ccc8182f8a1e86637b75a8fb1e717b157354 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Jan 2024 18:14:48 +0800
Subject: [PATCH] MIPS/clang: Fix asm constraint for softfloat

This include 2 fixes:
1. Disallow 'f' for softfloat.
2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: #64241
---
 clang/lib/Basic/Targets/Mips.h|  3 +++
 .../CodeGen/Mips/inline-asm-constraints.c | 18 +
 clang/test/Sema/inline-asm-validate-mips.c|  8 ++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 10 +---
 .../Mips/inlineasm-constraints-softfloat.ll   | 25 +++
 5 files changed, 61 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/Mips/inline-asm-constraints.c
 create mode 100644 clang/test/Sema/inline-asm-validate-mips.c
 create mode 100644 llvm/test/CodeGen/Mips/inlineasm-constraints-softfloat.ll

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f46b95abfd75c..2b8ad6645e605 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 case 'd': // Equivalent to "r" unless generating MIPS16 code.
 case 'y': // Equivalent to "r", backward compatibility only.
 case 'f': // floating-point registers.
+  if (*Name == 'f' && FloatABI == SoftFloat)
+return false;
+  LLVM_FALLTHROUGH;
 case 'c': // $25 for indirect jumps
 case 'l': // lo register
 case 'x': // hilo register pair
diff --git a/clang/test/CodeGen/Mips/inline-asm-constraints.c 
b/clang/test/CodeGen/Mips/inline-asm-constraints.c
new file mode 100644
index 0..0a4cb0b34570e
--- /dev/null
+++ b/clang/test/CodeGen/Mips/inline-asm-constraints.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -triple mips -target-feature +soft-float \
+// RUN:-DSOFT_FLOAT_CONSTRAINT_R \
+// RUN:-DFLOAT=float -emit-llvm -o - \
+// RUN:  | FileCheck %s --check-prefix SOFT_FLOAT_CONSTRAINT_R_SINGLE
+
+// RUN: %clang_cc1 %s -triple mips -target-feature +soft-float \
+// RUN:-DSOFT_FLOAT_CONSTRAINT_R \
+// RUN:-DFLOAT=double -emit-llvm -o - \
+// RUN:  | FileCheck %s --check-prefix SOFT_FLOAT_CONSTRAINT_R_DOUBLE
+
+#ifdef SOFT_FLOAT_CONSTRAINT_R
+// SOFT_FLOAT_CONSTRAINT_R_SINGLE: call void asm sideeffect "", 
"r,~{$1}"(float %2) #1, !srcloc !2
+// SOFT_FLOAT_CONSTRAINT_R_DOUBLE: call void asm sideeffect "", 
"r,~{$1}"(double %2) #1, !srcloc !2
+void read_float(FLOAT* p) {
+FLOAT result = *p;
+__asm__("" ::"r"(result));
+}
+#endif // SOFT_FLOAT_CONSTRAINT_R
diff --git a/clang/test/Sema/inline-asm-validate-mips.c 
b/clang/test/Sema/inline-asm-validate-mips.c
new file mode 100644
index 0..a56c75f0859a6
--- /dev/null
+++ b/clang/test/Sema/inline-asm-validate-mips.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple mips -target-feature +soft-float 
-DSOFT_FLOAT_NO_CONSTRAINT_F -fsyntax-only -verify %s
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float* p) {
+float result = *p;
+__asm__("" ::"f"(result)); // expected-error{{invalid input constraint 'f' 
in asm}}
+}
+#endif // SOFT_FLOAT_NO_CONSTRAINT_F
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index b2812f87914df..97e830cec27ca 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -4128,14 +4128,18 @@ MipsTargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'd': // Address register. Same as 'r' unless generating MIPS16 code.
 case 'y': // Same as 'r'. Exists for compatibility.
 case 'r':
-  if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 || VT == MVT::i1) {
+  if ((VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 ||
+   VT == MVT::i1) ||
+  (VT == MVT::f32 && Subtarget.useSoftFloat())) {
 if (Subtarget.inMips16Mode())
   return std::make_pair(0U, ::CPU16RegsRegClass);
 return std::make_pair(0U, ::GPR32RegClass);
   }
-  if (VT == MVT::i64 && !Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  !Subtarget.isGP64bit())
 return std::make_pair(0U, ::GPR32RegClass);
-  if (VT == MVT::i64 && Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  Subtarget.isGP64bit())
 return std::make_pair(0U, ::GPR64RegClass);
   // This will generate an error message
   return std::make_pair(0U, nullptr);
diff --git a/llvm/test/CodeGen/Mips/inlineasm-constraints-softfloat.ll 

[clang] [llvm] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/79116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/79116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] MIPS/clang: Disallow constraint f for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/79116

>From 009bd230a51a1790e6691ae3f104f57af311272f Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Jan 2024 18:14:48 +0800
Subject: [PATCH] MIPS/clang: Fix asm constraint for softfloat

This include 2 fixes:
1. Disallow 'f' for softfloat.
2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: #64241
---
 clang/lib/Basic/Targets/Mips.h|  3 ++
 clang/test/Driver/mips-float.c| 47 +++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 10 +++--
 3 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f46b95abfd75c..2b8ad6645e605 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 case 'd': // Equivalent to "r" unless generating MIPS16 code.
 case 'y': // Equivalent to "r", backward compatibility only.
 case 'f': // floating-point registers.
+  if (*Name == 'f' && FloatABI == SoftFloat)
+return false;
+  LLVM_FALLTHROUGH;
 case 'c': // $25 for indirect jumps
 case 'l': // lo register
 case 'x': // hilo register pair
diff --git a/clang/test/Driver/mips-float.c b/clang/test/Driver/mips-float.c
index 2f1b813a15322..34cf7fdfb9b79 100644
--- a/clang/test/Driver/mips-float.c
+++ b/clang/test/Driver/mips-float.c
@@ -102,3 +102,50 @@
 // CHECK-ABI-SOFT-MIPS16: "-target-feature" "+mips16"
 // CHECK-ABI-SOFT-MIPS16: "-msoft-float"
 // CHECK-ABI-SOFT-MIPS16: "-mfloat-abi" "soft"
+
+/// On MIPS, don't accept constraint "f" for soft-float.
+// RUN: not %clang -S %s -o %t.s 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float \
+// RUN: -DSOFT_FLOAT_NO_CONSTRAINT_F \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-NO-F %s
+// CHECK-SOFTFLOAT-ASM-NO-F: error: invalid input constraint 'f' in asm
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float* p) {
+float result = *p;
+__asm__("" ::"f"(result));
+}
+#endif // SOFT_FLOAT_NO_CONSTRAINT_F
+
+/// On MIPS, accept constraint "r" for soft-float.
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=32 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=float \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-3232 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-3232: lw  $2, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=32 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=double \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-3264 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-3264: lw  $2, 4($4)
+// CHECK-SOFTFLOAT-ASM-USE-R-3264: lw  $3, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=64 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=float \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-6432 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-6432: lw  $2, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=64 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=double \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-6464 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-6464: ld  $2, 0($4)
+
+#ifdef SOFT_FLOAT_USE_CONSTRAINT_R
+void read_float(FLOAT* p) {
+FLOAT result = *p;
+__asm__("" ::"r"(result));
+}
+#endif // SOFT_FLOAT_USE_CONSTRAINT_R
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index b2812f87914df..97e830cec27ca 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -4128,14 +4128,18 @@ MipsTargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'd': // Address register. Same as 'r' unless generating MIPS16 code.
 case 'y': // Same as 'r'. Exists for compatibility.
 case 'r':
-  if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 || VT == MVT::i1) {
+  if ((VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 ||
+   VT == MVT::i1) ||
+  (VT == MVT::f32 && Subtarget.useSoftFloat())) {
 if (Subtarget.inMips16Mode())
   return std::make_pair(0U, ::CPU16RegsRegClass);
 return std::make_pair(0U, ::GPR32RegClass);
   }
-  if (VT == MVT::i64 && !Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  !Subtarget.isGP64bit())
 return std::make_pair(0U, ::GPR32RegClass);
-  if (VT == MVT::i64 && Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  Subtarget.isGP64bit())
 return 

[clang-tools-extra] [llvm] [clang] MIPS/clang: Disallow constraint f for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/79116

>From afacadad3f6654c60609a8d024ab9b6c0123195d Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Jan 2024 18:14:48 +0800
Subject: [PATCH] MIPS/clang: Fix asm constraint for softfloat

This include 2 fixes:
1. Disallow 'f' for softfloat.
2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: #64241
---
 clang/lib/Basic/Targets/Mips.h|  3 ++
 clang/test/Driver/mips-float.c| 47 +++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 10 +++--
 3 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f46b95abfd75c..2b8ad6645e605 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 case 'd': // Equivalent to "r" unless generating MIPS16 code.
 case 'y': // Equivalent to "r", backward compatibility only.
 case 'f': // floating-point registers.
+  if (*Name == 'f' && FloatABI == SoftFloat)
+return false;
+  LLVM_FALLTHROUGH;
 case 'c': // $25 for indirect jumps
 case 'l': // lo register
 case 'x': // hilo register pair
diff --git a/clang/test/Driver/mips-float.c b/clang/test/Driver/mips-float.c
index 2f1b813a15322..34cf7fdfb9b79 100644
--- a/clang/test/Driver/mips-float.c
+++ b/clang/test/Driver/mips-float.c
@@ -102,3 +102,50 @@
 // CHECK-ABI-SOFT-MIPS16: "-target-feature" "+mips16"
 // CHECK-ABI-SOFT-MIPS16: "-msoft-float"
 // CHECK-ABI-SOFT-MIPS16: "-mfloat-abi" "soft"
+
+/// On MIPS, don't accept constraint "f" for soft-float.
+// RUN: not %clang -S %s -o %t.s 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float \
+// RUN: -DSOFT_FLOAT_NO_CONSTRAINT_F \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-NO-F %s
+// CHECK-SOFTFLOAT-ASM-NO-F: error: invalid input constraint 'f' in asm
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float* p) {
+float result = *p;
+__asm__("" ::"f"(result));
+}
+#endif // SOFT_FLOAT_NO_CONSTRAINT_F
+
+/// On MIPS, accept constraint "r" for soft-float.
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=32 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=float \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-3232 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-3232: lw  $2, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=32 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=double \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-3264 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-3264: lw  $2, 4($4)
+// CHECK-SOFTFLOAT-ASM-USE-R-3264: lw  $3, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=64 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=float \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-6432 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-6432: lw  $2, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=64 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=double \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-6464 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-6464: ld  $2, 0($4)
+
+#ifdef SOFT_FLOAT_USE_CONSTRAINT_R
+void read_float(FLOAT* p) {
+FLOAT result = *p;
+__asm__("" ::"r"(result));
+}
+#endif // SOFT_FLOAT_USE_CONSTRAINT_R
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index d431d3d91494f..88b226eaaccfa 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -4128,14 +4128,18 @@ MipsTargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'd': // Address register. Same as 'r' unless generating MIPS16 code.
 case 'y': // Same as 'r'. Exists for compatibility.
 case 'r':
-  if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 || VT == MVT::i1) {
+  if ((VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 ||
+   VT == MVT::i1) ||
+  (VT == MVT::f32 && Subtarget.useSoftFloat())) {
 if (Subtarget.inMips16Mode())
   return std::make_pair(0U, ::CPU16RegsRegClass);
 return std::make_pair(0U, ::GPR32RegClass);
   }
-  if (VT == MVT::i64 && !Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  !Subtarget.isGP64bit())
 return std::make_pair(0U, ::GPR32RegClass);
-  if (VT == MVT::i64 && Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  Subtarget.isGP64bit())
 return 

[llvm] [clang] MIPS/clang: Disallow constraint f for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa edited 
https://github.com/llvm/llvm-project/pull/79116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] MIPS/clang: Disallow constraint f for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/79116

>From afacadad3f6654c60609a8d024ab9b6c0123195d Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Jan 2024 18:14:48 +0800
Subject: [PATCH] MIPS/clang: Fix asm constraint for softfloat

This include 2 fixes:
1. Disallow 'f' for softfloat.
2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: #64241
---
 clang/lib/Basic/Targets/Mips.h|  3 ++
 clang/test/Driver/mips-float.c| 47 +++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 10 +++--
 3 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f46b95abfd75c..2b8ad6645e605 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 case 'd': // Equivalent to "r" unless generating MIPS16 code.
 case 'y': // Equivalent to "r", backward compatibility only.
 case 'f': // floating-point registers.
+  if (*Name == 'f' && FloatABI == SoftFloat)
+return false;
+  LLVM_FALLTHROUGH;
 case 'c': // $25 for indirect jumps
 case 'l': // lo register
 case 'x': // hilo register pair
diff --git a/clang/test/Driver/mips-float.c b/clang/test/Driver/mips-float.c
index 2f1b813a15322..34cf7fdfb9b79 100644
--- a/clang/test/Driver/mips-float.c
+++ b/clang/test/Driver/mips-float.c
@@ -102,3 +102,50 @@
 // CHECK-ABI-SOFT-MIPS16: "-target-feature" "+mips16"
 // CHECK-ABI-SOFT-MIPS16: "-msoft-float"
 // CHECK-ABI-SOFT-MIPS16: "-mfloat-abi" "soft"
+
+/// On MIPS, don't accept constraint "f" for soft-float.
+// RUN: not %clang -S %s -o %t.s 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float \
+// RUN: -DSOFT_FLOAT_NO_CONSTRAINT_F \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-NO-F %s
+// CHECK-SOFTFLOAT-ASM-NO-F: error: invalid input constraint 'f' in asm
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float* p) {
+float result = *p;
+__asm__("" ::"f"(result));
+}
+#endif // SOFT_FLOAT_NO_CONSTRAINT_F
+
+/// On MIPS, accept constraint "r" for soft-float.
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=32 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=float \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-3232 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-3232: lw  $2, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=32 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=double \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-3264 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-3264: lw  $2, 4($4)
+// CHECK-SOFTFLOAT-ASM-USE-R-3264: lw  $3, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=64 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=float \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-6432 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-6432: lw  $2, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=64 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=double \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-6464 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-6464: ld  $2, 0($4)
+
+#ifdef SOFT_FLOAT_USE_CONSTRAINT_R
+void read_float(FLOAT* p) {
+FLOAT result = *p;
+__asm__("" ::"r"(result));
+}
+#endif // SOFT_FLOAT_USE_CONSTRAINT_R
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index d431d3d91494f..88b226eaaccfa 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -4128,14 +4128,18 @@ MipsTargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'd': // Address register. Same as 'r' unless generating MIPS16 code.
 case 'y': // Same as 'r'. Exists for compatibility.
 case 'r':
-  if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 || VT == MVT::i1) {
+  if ((VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 ||
+   VT == MVT::i1) ||
+  (VT == MVT::f32 && Subtarget.useSoftFloat())) {
 if (Subtarget.inMips16Mode())
   return std::make_pair(0U, ::CPU16RegsRegClass);
 return std::make_pair(0U, ::GPR32RegClass);
   }
-  if (VT == MVT::i64 && !Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  !Subtarget.isGP64bit())
 return std::make_pair(0U, ::GPR32RegClass);
-  if (VT == MVT::i64 && Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  Subtarget.isGP64bit())
 return 

[clang] MIPS/clang: Disallow constraint f for softfloat (PR #79116)

2024-01-24 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

@MaskRay 

https://github.com/llvm/llvm-project/pull/79116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] MIPS/clang: Disallow constraint f for softfloat (PR #79116)

2024-01-23 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/79116

Currently, clang accpets contraint f for softfloat, then LLVM meet an internal 
error.

See: #64241

>From f01ce8f18a8cfaed41b4cfdd8b039abfc76aefd4 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Jan 2024 18:14:48 +0800
Subject: [PATCH] MIPS/clang: Disallow constraint f for softfloat

Currently, clang accpets contraint f for softfloat, then
LLVM meet an internal error.

See: #64241
---
 clang/lib/Basic/Targets/Mips.h |  3 +++
 clang/test/Driver/mips-float.c | 14 ++
 2 files changed, 17 insertions(+)

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f46b95abfd75c73..2b8ad6645e605fc 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 case 'd': // Equivalent to "r" unless generating MIPS16 code.
 case 'y': // Equivalent to "r", backward compatibility only.
 case 'f': // floating-point registers.
+  if (*Name == 'f' && FloatABI == SoftFloat)
+return false;
+  LLVM_FALLTHROUGH;
 case 'c': // $25 for indirect jumps
 case 'l': // lo register
 case 'x': // hilo register pair
diff --git a/clang/test/Driver/mips-float.c b/clang/test/Driver/mips-float.c
index 2f1b813a153224c..bbf17abfb13839f 100644
--- a/clang/test/Driver/mips-float.c
+++ b/clang/test/Driver/mips-float.c
@@ -102,3 +102,17 @@
 // CHECK-ABI-SOFT-MIPS16: "-target-feature" "+mips16"
 // CHECK-ABI-SOFT-MIPS16: "-msoft-float"
 // CHECK-ABI-SOFT-MIPS16: "-mfloat-abi" "soft"
+
+/// On MIPS, don't accept constraint "f" for soft-float.
+// RUN: not %clang -S %s -o %t.s 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float \
+// RUN: -DSOFT_FLOAT_NO_CONSTRAINT_F \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-NO-F %s
+// CHECK-SOFTFLOAT-ASM-NO-F: error: invalid input constraint 'f' in asm
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float* p) {
+float result = *p;
+__asm__("" ::"f"(result));
+}
+#endif // SOFT_FLOAT_NO_CONSTRAINT_F

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] Sanitizer prer6 (PR #76894)

2024-01-03 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

@brad0 

https://github.com/llvm/llvm-project/pull/76894
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] Sanitizer prer6 (PR #76894)

2024-01-03 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/76894

On MIPS pre-R6, instruction b can only work within 64KiB,
which is not enough now.

We need the help of GOT.
For __mips64, we can get GOT by:

   lui $t8, %hi(%neg(%gp_rel(SANITIZER_STRINGIFY(TRAMPOLINE(func)
   daddu $t8, $t8, $t9
   daddiu $t8, $t8, %hi(%neg(%gp_rel(SANITIZER_STRINGIFY(TRAMPOLINE(func)

And then get the address of __interceptor_func, and jump to it

   ld $t9, %got_disp(__interceptor_" SANITIZER_STRINGIFY(func) ")($t8)
   jr $t9

MIPS/O32 has .cpload, which can help to generate 3 instructions to get GOT.

MIPSr6 has instruction bc, which can jump long enough.

>From 4e1b075a26db2831d981bad61ae883ede890bd58 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Fri, 3 Nov 2023 03:30:52 -0400
Subject: [PATCH 1/2] Clang/MIPS: Use -mnan value for -mabs if not specified

On most hardware, FCSR.ABS2008 is set the value same with FCSR.NAN2008.
Let's use this behaivor by default.

With this commit, `clang -target mips -mnan=2008 -c fabs.c` will
imply `-mabs=2008`.

And of course, `clang -mnan=2008 -mabs=legacy` can continue workable
like previous.
---
 clang/lib/Driver/ToolChains/Arch/Mips.cpp | 8 ++--
 clang/test/Driver/mips-features.c | 8 +++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp 
b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index f9f14c01b2b9f0..fe9d112b8800b1 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -221,6 +221,7 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
   bool IsN64 = ABIName == "64";
   bool IsPIC = false;
   bool NonPIC = false;
+  bool HasNaN2008Opt = false;
 
   Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
 options::OPT_fpic, options::OPT_fno_pic,
@@ -285,9 +286,10 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
   if (Arg *A = Args.getLastArg(options::OPT_mnan_EQ)) {
 StringRef Val = StringRef(A->getValue());
 if (Val == "2008") {
-  if (mips::getIEEE754Standard(CPUName) & mips::Std2008)
+  if (mips::getIEEE754Standard(CPUName) & mips::Std2008) {
 Features.push_back("+nan2008");
-  else {
+HasNaN2008Opt = true;
+  } else {
 Features.push_back("-nan2008");
 D.Diag(diag::warn_target_unsupported_nan2008) << CPUName;
   }
@@ -323,6 +325,8 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
   D.Diag(diag::err_drv_unsupported_option_argument)
   << A->getSpelling() << Val;
 }
+  } else if (HasNaN2008Opt) {
+Features.push_back("+abs2008");
   }
 
   AddTargetFeature(Args, Features, options::OPT_msingle_float,
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index 5ae566774959f1..fad6009ffb89ba 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -213,7 +213,13 @@
 // RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \
 // RUN: -mnan=legacy -mnan=2008 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NAN2008 %s
-// CHECK-NAN2008: "-target-feature" "+nan2008"
+// CHECK-NAN2008: "-target-feature" "+nan2008" "-target-feature" "+abs2008"
+//
+// -mnan=2008 -mabs=legacy
+// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \
+// RUN: -mabs=legacy -mnan=2008 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ABSLEGACYNAN2008 %s
+// CHECK-ABSLEGACYNAN2008: "-target-feature" "+nan2008" "-target-feature" 
"-abs2008"
 //
 // -mnan=legacy
 // RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \

>From 9893b37053f02f679fcef2961b1e6872d8cf20b3 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Thu, 4 Jan 2024 13:07:41 +0800
Subject: [PATCH 2/2] Sanitizer/MIPS: fix build fail on pre-R6

On MIPS pre-R6, instruction b can only work within 64KiB,
which is not enough now.

We need the help of GOT.
For __mips64, we can get GOT by:

  lui $t8, %hi(%neg(%gp_rel(SANITIZER_STRINGIFY(TRAMPOLINE(func)
  daddu $t8, $t8, $t9
  daddiu $t8, $t8, %hi(%neg(%gp_rel(SANITIZER_STRINGIFY(TRAMPOLINE(func)

And then get the address of __interceptor_func, and jump to it

  ld $t9, %got_disp(__interceptor_" SANITIZER_STRINGIFY(func) ")($t8)
  jr $t9

MIPS/O32 has .cpload, which can help to generate 3 instructions to get GOT.

MIPSr6 has instruction bc, which can jump long enough.
---
 compiler-rt/lib/interception/interception.h   |  5 +++--
 .../lib/sanitizer_common/sanitizer_asm.h  | 21 +++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/interception/interception.h 
b/compiler-rt/lib/interception/interception.h
index 9d8b60b2eef58c..58e969378a9082 100644
--- a/compiler-rt/lib/interception/interception.h
+++ b/compiler-rt/lib/interception/interception.h
@@ -205,8 +205,9 @@ const interpose_substitution 

[clang] Clang/MIPS: Use -mnan value for -mabs if not specified (PR #71157)

2024-01-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/71157

>From 4e1b075a26db2831d981bad61ae883ede890bd58 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Fri, 3 Nov 2023 03:30:52 -0400
Subject: [PATCH] Clang/MIPS: Use -mnan value for -mabs if not specified

On most hardware, FCSR.ABS2008 is set the value same with FCSR.NAN2008.
Let's use this behaivor by default.

With this commit, `clang -target mips -mnan=2008 -c fabs.c` will
imply `-mabs=2008`.

And of course, `clang -mnan=2008 -mabs=legacy` can continue workable
like previous.
---
 clang/lib/Driver/ToolChains/Arch/Mips.cpp | 8 ++--
 clang/test/Driver/mips-features.c | 8 +++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp 
b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index f9f14c01b2b9f0..fe9d112b8800b1 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -221,6 +221,7 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
   bool IsN64 = ABIName == "64";
   bool IsPIC = false;
   bool NonPIC = false;
+  bool HasNaN2008Opt = false;
 
   Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
 options::OPT_fpic, options::OPT_fno_pic,
@@ -285,9 +286,10 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
   if (Arg *A = Args.getLastArg(options::OPT_mnan_EQ)) {
 StringRef Val = StringRef(A->getValue());
 if (Val == "2008") {
-  if (mips::getIEEE754Standard(CPUName) & mips::Std2008)
+  if (mips::getIEEE754Standard(CPUName) & mips::Std2008) {
 Features.push_back("+nan2008");
-  else {
+HasNaN2008Opt = true;
+  } else {
 Features.push_back("-nan2008");
 D.Diag(diag::warn_target_unsupported_nan2008) << CPUName;
   }
@@ -323,6 +325,8 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
   D.Diag(diag::err_drv_unsupported_option_argument)
   << A->getSpelling() << Val;
 }
+  } else if (HasNaN2008Opt) {
+Features.push_back("+abs2008");
   }
 
   AddTargetFeature(Args, Features, options::OPT_msingle_float,
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index 5ae566774959f1..fad6009ffb89ba 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -213,7 +213,13 @@
 // RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \
 // RUN: -mnan=legacy -mnan=2008 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NAN2008 %s
-// CHECK-NAN2008: "-target-feature" "+nan2008"
+// CHECK-NAN2008: "-target-feature" "+nan2008" "-target-feature" "+abs2008"
+//
+// -mnan=2008 -mabs=legacy
+// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \
+// RUN: -mabs=legacy -mnan=2008 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ABSLEGACYNAN2008 %s
+// CHECK-ABSLEGACYNAN2008: "-target-feature" "+nan2008" "-target-feature" 
"-abs2008"
 //
 // -mnan=legacy
 // RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] MIPS/libunwind: Use -mfp64 if compiler is FPXX (PR #68521)

2023-11-08 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

@brad0 can you have a look at this PR?

https://github.com/llvm/llvm-project/pull/68521
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Clang/MIPS: Use -mnan value for -mabs if not specified (PR #71157)

2023-11-08 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

@brad0 can you have a look at this?

https://github.com/llvm/llvm-project/pull/71157
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] MIPS/libunwind: Use -mfp64 if compiler is FPXX (PR #68521)

2023-11-03 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/68521

>From 6053822322fd1594b46bf77c8b168ad802a7c534 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Sun, 8 Oct 2023 07:12:45 -0400
Subject: [PATCH] MIPS/libunwind: Use -mfp64 if compiler is FPXX

Libunwind supports FP64 and FP32 modes, but not FPXX.
The reason is that, FP64 and FP32 have different way to save/restore
FPRs. If libunwind is built as FPXX, we have no idea which one should
we use.

If libunwind is built as FP64, it will interoperatable with FPXX/FP64
APPs, and if it is built as FP32, it will interoperatable with
FP32/FPXX. Currently most of O32 APPs are FPXX or FP64, while few are FP32.

So if the compiler is FPXX, which is the default value of most toolchain,
let's switch it to FP64.
---
 libunwind/CMakeLists.txt | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 84f8ce296a7410b..387d4b43b5746a6 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -21,6 +21,7 @@ set(LIBUNWIND_LIBCXX_PATH 
"${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
 "Specify path to libc++ source.")
 
 include(GNUInstallDirs)
+include(CheckSymbolExists)
 
 
#===
 # Setup CMake Options
@@ -101,6 +102,20 @@ endif()
 option(LIBUNWIND_HIDE_SYMBOLS
   "Do not export any symbols from the static library." 
${LIBUNWIND_DEFAULT_HIDE_SYMBOLS})
 
+# If toolchain is FPXX, we switch to FP64 to save the full FPRs. See:
+# 
https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
+check_symbol_exists(__mips_hard_float "" __MIPSHF)
+check_symbol_exists(_ABIO32 "" __MIPS_O32)
+if (__MIPSHF AND __MIPS_O32)
+  file(WRITE 
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
+"#if __mips_fpr != 0\n"
+"# error\n"
+"#endif\n")
+  try_compile(MIPS_FPABI_FPXX ${CMAKE_BINARY_DIR}
+${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
+CMAKE_FLAGS -DCMAKE_C_LINK_EXECUTABLE='echo')
+endif()
+
 
#===
 # Configure System
 
#===
@@ -184,6 +199,10 @@ if (WIN32)
   add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
 endif()
 
+if (MIPS_FPABI_FPXX)
+  add_compile_flags(-mfp64)
+endif()
+
 # Get feature flags.
 # Exceptions
 # Catches C++ exceptions only and tells the compiler to assume that extern C

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Clang/MIPS: Use -mnan value for -mabs if not specified (PR #71157)

2023-11-03 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/71157

On most hardware, FCSR.ABS2008 is set the value same with FCSR.NAN2008. Let's 
use this behaivor by default.

With this commit, `clang -target mips -mnan=2008 -c fabs.c` will imply 
`-mabs=2008`.

And of course, `clang -mnan=2008 -mabs=legacy` can continue workable like 
previous.

>From feabd6fd561ff7af2f21b7c649fe8a4cc1ac6343 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Fri, 3 Nov 2023 03:30:52 -0400
Subject: [PATCH] Clang/MIPS: Use -mnan value for -mabs if not specified

On most hardware, FCSR.ABS2008 is set the value same with FCSR.NAN2008.
Let's use this behaivor by default.

With this commit, `clang -target mips -mnan=2008 -c fabs.c` will
imply `-mabs=2008`.

And of course, `clang -mnan=2008 -mabs=legacy` can continue workable
like previous.
---
 clang/lib/Driver/ToolChains/Arch/Mips.cpp | 8 ++--
 clang/test/Driver/mips-features.c | 8 
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp 
b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index f9f14c01b2b9f01..fe9d112b8800b17 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -221,6 +221,7 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
   bool IsN64 = ABIName == "64";
   bool IsPIC = false;
   bool NonPIC = false;
+  bool HasNaN2008Opt = false;
 
   Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
 options::OPT_fpic, options::OPT_fno_pic,
@@ -285,9 +286,10 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
   if (Arg *A = Args.getLastArg(options::OPT_mnan_EQ)) {
 StringRef Val = StringRef(A->getValue());
 if (Val == "2008") {
-  if (mips::getIEEE754Standard(CPUName) & mips::Std2008)
+  if (mips::getIEEE754Standard(CPUName) & mips::Std2008) {
 Features.push_back("+nan2008");
-  else {
+HasNaN2008Opt = true;
+  } else {
 Features.push_back("-nan2008");
 D.Diag(diag::warn_target_unsupported_nan2008) << CPUName;
   }
@@ -323,6 +325,8 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
   D.Diag(diag::err_drv_unsupported_option_argument)
   << A->getSpelling() << Val;
 }
+  } else if (HasNaN2008Opt) {
+Features.push_back("+abs2008");
   }
 
   AddTargetFeature(Args, Features, options::OPT_msingle_float,
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index 5ae566774959f18..fc1b5894f539377 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -214,6 +214,14 @@
 // RUN: -mnan=legacy -mnan=2008 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NAN2008 %s
 // CHECK-NAN2008: "-target-feature" "+nan2008"
+// CHECK-NAN2008: "-target-feature" "+abs2008"
+//
+// -mnan=2008 -mabs=legacy
+// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \
+// RUN: -mabs=legacy -mnan=2008 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ABSLEGACYNAN2008 %s
+// CHECK-ABSLEGACYNAN2008: "-target-feature" "+nan2008"
+// CHECK-ABSLEGACYNAN2008: "-target-feature" "-abs2008"
 //
 // -mnan=legacy
 // RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] MIPS/libunwind: Use -mfp64 if compiler is FPXX (PR #68521)

2023-10-08 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/68521

Libunwind supports FP64 and FP32 modes, but not FPXX. The reason is that, FP64 
and FP32 have different way to save/restore FPRs. If libunwind is built as 
FPXX, we have no idea which one should we use.

If libunwind is built as FP64, it will interoperatable with FPXX/FP64 APPs, and 
if it is built as FP32, it will interoperatable with FP32/FPXX. Currently most 
of O32 APPs are FPXX or FP64, while few are FP32.

So if the compiler is FPXX, which is the default value of most toolchain, let's 
switch it to FP64.

>From dad17bc3806edd2055fae654a023f4c5473a8276 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Sun, 8 Oct 2023 07:12:45 -0400
Subject: [PATCH] MIPS/libunwind: Use -mfp64 if compiler is FPXX

Libunwind supports FP64 and FP32 modes, but not FPXX.
The reason is that, FP64 and FP32 have different way to save/restore
FPRs. If libunwind is built as FPXX, we have no idea which one should
we use.

If libunwind is built as FP64, it will interoperatable with FPXX/FP64
APPs, and if it is built as FP32, it will interoperatable with
FP32/FPXX. Currently most of O32 APPs are FPXX or FP64, while few are FP32.

So if the compiler is FPXX, which is the default value of most toolchain,
let's switch it to FP64.
---
 libunwind/CMakeLists.txt | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 84f8ce296a7410b..387d4b43b5746a6 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -21,6 +21,7 @@ set(LIBUNWIND_LIBCXX_PATH 
"${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
 "Specify path to libc++ source.")
 
 include(GNUInstallDirs)
+include(CheckSymbolExists)
 
 
#===
 # Setup CMake Options
@@ -101,6 +102,20 @@ endif()
 option(LIBUNWIND_HIDE_SYMBOLS
   "Do not export any symbols from the static library." 
${LIBUNWIND_DEFAULT_HIDE_SYMBOLS})
 
+# If toolchain is FPXX, we switch to FP64 to save the full FPRs. See:
+# 
https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
+check_symbol_exists(__mips_hard_float "" __MIPSHF)
+check_symbol_exists(_ABIO32 "" __MIPS_O32)
+if (__MIPSHF AND __MIPS_O32)
+  file(WRITE 
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
+"#if __mips_fpr != 0\n"
+"# error\n"
+"#endif\n")
+  try_compile(MIPS_FPABI_FPXX ${CMAKE_BINARY_DIR}
+${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
+CMAKE_FLAGS -DCMAKE_C_LINK_EXECUTABLE='echo')
+endif()
+
 
#===
 # Configure System
 
#===
@@ -184,6 +199,10 @@ if (WIN32)
   add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
 endif()
 
+if (MIPS_FPABI_FPXX)
+  add_compile_flags(-mfp64)
+endif()
+
 # Get feature flags.
 # Exceptions
 # Catches C++ exceptions only and tells the compiler to assume that extern C

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D50850: clang: Add triples support for MIPS r6

2018-09-27 Thread YunQiang Su via cfe-commits
I updated N32 patch for clang.
Simon Atanasyan via Phabricator 
于2018年9月27日周四 下午8:23写道:
>
> atanasyan added a comment.
>
> Could you please update the patch against the current trunk?
>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D50850
>
>
>


-- 
YunQiang Su
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits