[PATCH] D136413: [Clang][LoongArch] Define more LoongArch specific built-in macros

2022-10-20 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

I've formatted the patch summary for you. Please familiarize yourself with 
Markdown syntax so next time your rendering would look better.

In D136413#3873317 , @tangyouling 
wrote:

> Do we need to add the definition of the `__loongarch64` macro? gcc has that 
> definition (but it is not recommended to use it, just for compatibility with 
> previous code).
> It has been used in some projects before, such as linux kernel, libunwind etc.

For minimum churn and hassle, I'm afraid we have to add it for now. I didn't 
realize [[ 
https://github.com/loongson/LoongArch-Documentation/pull/28#discussion_r917367794
 | it's the equivalent of `__mips64` ]] until too much software has been ported 
with it...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136413/new/

https://reviews.llvm.org/D136413

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


[PATCH] D136436: [Clang][LoongArch] Add register alias handling without `$` prefix

2022-10-21 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

Commit message is unclear. You added non-prefixed aliases for all registers, 
yet only `$a0` is mentioned. I'd like to see what improvement you could come up 
with before amending it myself, to hopefully make you better at writing those 
"small compositions".




Comment at: clang/lib/Basic/Targets/LoongArch.cpp:52
+  {{"t8", "$t8", "r20"}, "$r20"},{{"r21"}, "$r21"},
+  {{"fp", "$fp", "r22", "$s9"}, "$r22"}, {{"s0", "$s0", "r23"}, "$r23"},
+  {{"s1", "$s1", "r24"}, "$r24"},{{"s2", "$s2", "r25"}, "$r25"},

Missing `"s9"`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136436/new/

https://reviews.llvm.org/D136436

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


[PATCH] D136436: [Clang][LoongArch] Add register alias handling without `$` prefix

2022-10-21 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

In D136436#3873949 , @SixWeining 
wrote:

> How about the asm code in `.s`? Do we need to support `addi.d a0, a1, a2`?

For the assembler part of this support, I think we need to coordinate with the 
GNU toolchain maintainers of LoongArch port (Chenghua, Zhensong and Lulu I 
think). Maybe raising an issue on the LoongArch documentation repo 
 would help.

For the GCC part, consistency is of course welcomed, and I think the Loongson 
maintainers or @xry111 could just submit the respective support.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136436/new/

https://reviews.llvm.org/D136436

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


[PATCH] D136436: [Clang][LoongArch] Add register alias handling without `$` prefix

2022-10-27 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

In D136436#3890737 , @SixWeining 
wrote:

> In D136436#3881382 , @MaskRay wrote:
>
>> In D136436#3876684 , @SixWeining 
>> wrote:
>>
>>> In D136436#3873987 , @xen0n wrote:
>>>
 In D136436#3873949 , @SixWeining 
 wrote:

> How about the asm code in `.s`? Do we need to support `addi.d a0, a1, a2`?

 For the assembler part of this support, I think we need to coordinate with 
 the GNU toolchain maintainers of LoongArch port (Chenghua, Zhensong and 
 Lulu I think). Maybe raising an issue on the LoongArch documentation repo 
  would help.

 For the GCC part, consistency is of course welcomed, and I think the 
 Loongson maintainers or @xry111 could just submit the respective support.
>>>
>>> Well. To be honest, I'd like to keep only one form but not both. Seems 
>>> other archs only support one form? If we support both, will it make people 
>>> confused?  Is mixed form allowed (`fmadd.d fa0, $fa0, f0, $fcc0`) ?
>>
>> Having just one form will be nice.
>
> @tangyouling Considering that `$`  is well supported by both gcc and llvm, we 
> should adandon this patch?

I'm afraid no, the prefix-less form is AFAIK likely inspired by RISC-V assembly 
(which doesn't have any prefix for registers whatsoever), but the `$`-prefixed 
form is clearly a MIPS style, and frankly speaking we (the community) had no 
choice at the time of binutils upstreaming because of the insistence of 
Chenghua et al., and loads of code using the prefixed form already appearing. 
The important point is that there's already code making use of prefix-less 
register names in inline asm, so we must follow suit for keeping source 
compatibility across gcc and clang.

While having just one form to support is indeed nice, that ship has sailed long 
ago, and I think the next best thing is to allow both styles but disallow 
mixing of styles in one insn, i.e. no things like `add $a0, a1, $a2`, if it's 
impossible to only allow prefix-less register names in Clang inline asm but not 
at LLVM level.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136436/new/

https://reviews.llvm.org/D136436

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


[PATCH] D136841: [LoongArch] Support inline asm operand modifier 'z'

2022-10-29 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

Inching closer to ClangBuiltLinux on LoongArch it seems!




Comment at: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp:64
+  break;
+  // TODO: handle other extra codes if we have.
 }

nit: "if any"


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136841/new/

https://reviews.llvm.org/D136841

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


[PATCH] D136841: [LoongArch] Support inline asm operand modifier 'z'

2022-10-29 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

Ah. There's a typo in the name of the testcase file...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136841/new/

https://reviews.llvm.org/D136841

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


[PATCH] D136413: [Clang][LoongArch] Define more LoongArch specific built-in macros

2022-10-30 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

Amended the patch summary a little for grammatical fixes and mentioning 
`__loongarch64` too.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136413/new/

https://reviews.llvm.org/D136413

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


[PATCH] D136146: [Clang][LoongArch] Handle -march/-m{single,double,soft}-float/-mfpu options

2022-10-30 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

Looks good LoongArch-wise but I'm not very familiar with Clang internals to 
start with. Might be okay to land since this touches little code outside 
LoongArch and has passed tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136146/new/

https://reviews.llvm.org/D136146

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


[PATCH] D130255: [Clang][LoongArch] Add initial LoongArch target and driver support

2022-08-21 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2236
 
+  static const char *const LoongArch64LibDirs[] = {"/lib64", "/lib"};
+  static const char *const LoongArch64Triples[] = {

FWIW this is actually beneficial for Gentoo (which consistently uses `lib64` 
for its 64-bit-capable profiles since forever, at least for all of the 64-bit 
arches/profiles I have used). Otherwise the libdir is really more-or-less 
freely chosen. And I think most if not all distros already patch downstream for 
this libdir tweaking...

The ELF interpreter path is indeed hardcoded, and I'll admit I referred to many 
`lib64`-using precedents when reviewing the initial proposal. I think many 
ideas were thrown around and every of them was strictly better than the MIPS 
carryover `/lib/ld.so.1` I think. That ship has long sailed though, and even a 
`lib64` just for housing the symlink to the real `ld.so` seems okay to me.

So overall personally I don't feel this is too problematic; sorry if I sounded 
like a grumpy old guy defending his favorite `/lib64` (and all its old 
split-usr glory ;-)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130255/new/

https://reviews.llvm.org/D130255

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


[PATCH] D134157: [LoongArch] Add inline asm support for constraints f/l/I/K

2022-09-21 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

I don't know if the clang changes should be split into its own commit (or the 
title of this commit amended to mention `[Clang]` but I don't know if this is 
appropriate), but the rest looks reasonable.




Comment at: llvm/test/CodeGen/LoongArch/inline-asm-constraint-error.ll:2
+; RUN: not llc -mtriple=loongarch32 < %s 2>&1 | FileCheck %s
+; RUN: not llc -mtriple=loongarch64 < %s 2>&1 | FileCheck %s
+

double dashes for `--mtriple`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134157/new/

https://reviews.llvm.org/D134157

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


[PATCH] D134638: [Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC

2022-09-26 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

The test cases look good to me. We should be pretty close to passing `ninja 
check` natively. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134638/new/

https://reviews.llvm.org/D134638

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


[PATCH] D134638: [Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC

2022-09-29 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

The previous test results (with some of my WIP patches but unrelated to this) 
before the fix:

  Failed Tests (6):
LLVM :: CodeGen/AArch64/GlobalISel/irtranslator-inline-asm.ll
LLVM :: CodeGen/AMDGPU/GlobalISel/irtranslator-inline-asm.ll
LLVM :: CodeGen/Generic/vector.ll
LLVM :: CodeGen/PowerPC/2007-11-19-VectorSplitting.ll
LLVM :: CodeGen/X86/callbr-asm-kill.mir
LLVM :: DebugInfo/Generic/missing-abstract-variable.ll

Sure enough it was caught by my native build with all targets enabled, anyway 
it's important to at least enable the "big" targets such as X86 and AArch64 
when configuring the local dev env. ;-)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134638/new/

https://reviews.llvm.org/D134638

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


[PATCH] D140685: [LoongArch] Add intrinsics for MOVFCSR2GR and MOVGR2FCSR instructions

2022-12-27 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

> MOVGR2FCSR modifies the value of the software writable field
> corresponding to the FCSR (floating-point control and status
> register) fcsr according to the value of the lower 32 bits of
> the GR (general purpose register) rj.

The description of `movgr2fcsr` is incorrect, it implies `GPR[rj]`is read, but 
in fact it's only the //`ui5` immediate in `rj` slot//, i.e. `FCSR[rj]`. I 
didn't look very closely but the test case changes seem good.

(It's probably more appropriate to name the instructions `fcsrrd` and `fcsrwr` 
(as done in loongarch-opcodes 
)
 but it may be hard to officially revise the ISA manual according to some of 
Loongson insiders. Maybe we can use the corrected names in the internals and 
expose the official name for now? This is just a suggestion for your teammates 
to consider though.)




Comment at: llvm/lib/Target/LoongArch/LoongArchInstrInfo.td:53
+SDTCisVT<1, GRLenVT>]>;
+def SDT_LoongArchFCSR2GR : SDTypeProfile<1, 1, [SDTCisVT<0, GRLenVT>,
+SDTCisVT<1, i32>]>;

Be consistent with the surrounding code and spell out the instruction mnemonic 
fully? Like `SDT_LoongArchMovfcsr2gr`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140685/new/

https://reviews.llvm.org/D140685

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


[PATCH] D140685: [LoongArch] Add intrinsics for MOVFCSR2GR and MOVGR2FCSR instructions

2023-01-03 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.

In D140685#4017381 , @xen0n wrote:

>> MOVGR2FCSR modifies the value of the software writable field
>> corresponding to the FCSR (floating-point control and status
>> register) fcsr according to the value of the lower 32 bits of
>> the GR (general purpose register) rj.
>
> The description of `movgr2fcsr` is incorrect, it implies `GPR[rj]`is read, 
> but in fact it's only the //`ui5` immediate in `rj` slot//, i.e. `FCSR[rj]`. 
> I didn't look very closely but the test case changes seem good.

On a closer look it turns out the description is correct after all, the 
description is very much non-intuitive (uses just `fcsr` without any position 
marker) so I've mistaken the GPR operand for the FCSR slot. This is very 
unfortunate but luckily users of the intrinsics won't have to think about it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140685/new/

https://reviews.llvm.org/D140685

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


[PATCH] D142688: [Clang][Driver] Handle LoongArch multiarch tuples

2023-01-26 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n created this revision.
xen0n added reviewers: SixWeining, wangleiat, MaskRay, xry111.
Herald added a project: All.
xen0n requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This follows v1.00 of the LoongArch Toolchain Conventions 
.

Only `loongarch64` is implemented in `Linux::getMultiarchTriple`
because support for LA32 and ILP32* ABIs are incomplete right now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142688

Files:
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/loongarch-abi.c


Index: clang/test/Driver/loongarch-abi.c
===
--- clang/test/Driver/loongarch-abi.c
+++ clang/test/Driver/loongarch-abi.c
@@ -16,6 +16,26 @@
 // RUN: %clang --target=loongarch64-unknown-elf %s -fsyntax-only -### 
-mabi=lp64d 2>&1 \
 // RUN:   | FileCheck --check-prefix=LP64D %s
 
+// RUN: %clang --target=loongarch32-linux-gnusf %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32S %s
+// RUN: %clang --target=loongarch32-linux-gnuf32 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32F %s
+// RUN: %clang --target=loongarch32-linux-gnuf64 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32D %s
+
+// RUN: %clang --target=loongarch64-linux-gnusf %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64S %s
+// RUN: %clang --target=loongarch64-linux-gnuf32 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64F %s
+// RUN: %clang --target=loongarch64-linux-gnuf64 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64D %s
+
+// Check that -mabi prevails in case of conflicts with the triple-implied ABI.
+// RUN: %clang --target=loongarch32-linux-gnuf64 %s -fsyntax-only -### 
-mabi=ilp32s 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32S %s
+// RUN: %clang --target=loongarch64-linux-gnuf64 %s -fsyntax-only -### 
-mabi=lp64s 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64S %s
+
 // ILP32S: "-target-abi" "ilp32s"
 // ILP32F: "-target-abi" "ilp32f"
 // ILP32D: "-target-abi" "ilp32d"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -86,6 +86,36 @@
   case llvm::Triple::aarch64_be:
 return "aarch64_be-linux-gnu";
 
+  case llvm::Triple::loongarch64: {
+const char *Libc;
+const char *FPFlavor;
+
+if (TargetTriple.isGNUEnvironment()) {
+  Libc = "gnu";
+} else if (TargetTriple.isMusl()) {
+  Libc = "musl";
+} else {
+  return TargetTriple.str();
+}
+
+switch (TargetEnvironment) {
+default:
+  return TargetTriple.str();
+case llvm::Triple::GNUSF:
+  FPFlavor = "sf";
+  break;
+case llvm::Triple::GNUF32:
+  FPFlavor = "f32";
+  break;
+case llvm::Triple::GNU:
+case llvm::Triple::GNUF64:
+  FPFlavor = "f64";
+  break;
+}
+
+return std::string("loongarch64-linux-") + Libc + FPFlavor;
+  }
+
   case llvm::Triple::m68k:
 return "m68k-linux-gnu";
 
Index: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
===
--- clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -54,7 +54,17 @@
   }
 
   // Choose a default based on the triple.
-  return IsLA32 ? "ilp32d" : "lp64d";
+  // Honor the explicit ABI modifier suffix in triple's environment part if
+  // present, falling back to {ILP32,LP64}D otherwise.
+  switch (Triple.getEnvironment()) {
+  case llvm::Triple::GNUSF:
+return IsLA32 ? "ilp32s" : "lp64s";
+  case llvm::Triple::GNUF32:
+return IsLA32 ? "ilp32f" : "lp64f";
+  case llvm::Triple::GNUF64:
+  default:
+return IsLA32 ? "ilp32d" : "lp64d";
+  }
 }
 
 void loongarch::getLoongArchTargetFeatures(const Driver &D,


Index: clang/test/Driver/loongarch-abi.c
===
--- clang/test/Driver/loongarch-abi.c
+++ clang/test/Driver/loongarch-abi.c
@@ -16,6 +16,26 @@
 // RUN: %clang --target=loongarch64-unknown-elf %s -fsyntax-only -### -mabi=lp64d 2>&1 \
 // RUN:   | FileCheck --check-prefix=LP64D %s
 
+// RUN: %clang --target=loongarch32-linux-gnusf %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32S %s
+// RUN: %clang --target=loongarch32-linux-gnuf32 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32F %s
+// RUN: %clang --target=loongarch32-linux-gnuf64 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32D %s
+
+// RUN: %clang --target=loongarch64-linux-gnusf %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64S %s
+// RUN: %clang --targ

[PATCH] D142688: [Clang][Driver] Handle LoongArch multiarch tuples

2023-01-31 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n updated this revision to Diff 493796.
xen0n added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142688/new/

https://reviews.llvm.org/D142688

Files:
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/loongarch-abi.c


Index: clang/test/Driver/loongarch-abi.c
===
--- clang/test/Driver/loongarch-abi.c
+++ clang/test/Driver/loongarch-abi.c
@@ -16,6 +16,26 @@
 // RUN: %clang --target=loongarch64-unknown-elf %s -fsyntax-only -### 
-mabi=lp64d 2>&1 \
 // RUN:   | FileCheck --check-prefix=LP64D %s
 
+// RUN: %clang --target=loongarch32-linux-gnusf %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32S %s
+// RUN: %clang --target=loongarch32-linux-gnuf32 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32F %s
+// RUN: %clang --target=loongarch32-linux-gnuf64 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32D %s
+
+// RUN: %clang --target=loongarch64-linux-gnusf %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64S %s
+// RUN: %clang --target=loongarch64-linux-gnuf32 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64F %s
+// RUN: %clang --target=loongarch64-linux-gnuf64 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64D %s
+
+// Check that -mabi prevails in case of conflicts with the triple-implied ABI.
+// RUN: %clang --target=loongarch32-linux-gnuf64 %s -fsyntax-only -### 
-mabi=ilp32s 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32S %s
+// RUN: %clang --target=loongarch64-linux-gnuf64 %s -fsyntax-only -### 
-mabi=lp64s 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64S %s
+
 // ILP32S: "-target-abi" "ilp32s"
 // ILP32F: "-target-abi" "ilp32f"
 // ILP32D: "-target-abi" "ilp32d"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -86,6 +86,36 @@
   case llvm::Triple::aarch64_be:
 return "aarch64_be-linux-gnu";
 
+  case llvm::Triple::loongarch64: {
+const char *Libc;
+const char *FPFlavor;
+
+if (TargetTriple.isGNUEnvironment()) {
+  Libc = "gnu";
+} else if (TargetTriple.isMusl()) {
+  Libc = "musl";
+} else {
+  return TargetTriple.str();
+}
+
+switch (TargetEnvironment) {
+default:
+  return TargetTriple.str();
+case llvm::Triple::GNUSF:
+  FPFlavor = "sf";
+  break;
+case llvm::Triple::GNUF32:
+  FPFlavor = "f32";
+  break;
+case llvm::Triple::GNU:
+case llvm::Triple::GNUF64:
+  FPFlavor = "f64";
+  break;
+}
+
+return std::string("loongarch64-linux-") + Libc + FPFlavor;
+  }
+
   case llvm::Triple::m68k:
 return "m68k-linux-gnu";
 
Index: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
===
--- clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -54,7 +54,17 @@
   }
 
   // Choose a default based on the triple.
-  return IsLA32 ? "ilp32d" : "lp64d";
+  // Honor the explicit ABI modifier suffix in triple's environment part if
+  // present, falling back to {ILP32,LP64}D otherwise.
+  switch (Triple.getEnvironment()) {
+  case llvm::Triple::GNUSF:
+return IsLA32 ? "ilp32s" : "lp64s";
+  case llvm::Triple::GNUF32:
+return IsLA32 ? "ilp32f" : "lp64f";
+  case llvm::Triple::GNUF64:
+  default:
+return IsLA32 ? "ilp32d" : "lp64d";
+  }
 }
 
 void loongarch::getLoongArchTargetFeatures(const Driver &D,


Index: clang/test/Driver/loongarch-abi.c
===
--- clang/test/Driver/loongarch-abi.c
+++ clang/test/Driver/loongarch-abi.c
@@ -16,6 +16,26 @@
 // RUN: %clang --target=loongarch64-unknown-elf %s -fsyntax-only -### -mabi=lp64d 2>&1 \
 // RUN:   | FileCheck --check-prefix=LP64D %s
 
+// RUN: %clang --target=loongarch32-linux-gnusf %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32S %s
+// RUN: %clang --target=loongarch32-linux-gnuf32 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32F %s
+// RUN: %clang --target=loongarch32-linux-gnuf64 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32D %s
+
+// RUN: %clang --target=loongarch64-linux-gnusf %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64S %s
+// RUN: %clang --target=loongarch64-linux-gnuf32 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64F %s
+// RUN: %clang --target=loongarch64-linux-gnuf64 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64D %s
+
+// Check that -mabi prevails in case of conflicts with the triple-implied ABI.
+// RUN: %clang --target=loongarch32-linux-gnuf64 %s -fsyntax-only

[PATCH] D142688: [Clang][Driver] Handle LoongArch multiarch tuples

2023-01-31 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added inline comments.



Comment at: clang/lib/Driver/ToolChains/Linux.cpp:41
 /// so we provide a rough mapping here.
 std::string Linux::getMultiarchTriple(const Driver &D,
   const llvm::Triple &TargetTriple,

SixWeining wrote:
> Missing test. Perhaps add some in `clang/test/Driver/linux-ld.c` and 
> `clang/test/Driver/linux-header-search.cpp`? Or postpone this change until 
> loongarch is upstreamed to Debian?
Thanks, I'll try adding the tests in the next revision.

But given [[ https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1028654 | the 
recent reversal of upstream dpkg support ]] (apparently due to 
miscommunication) it may be prudent to wait until a consensus is reached 
Debian-side.



Comment at: clang/lib/Driver/ToolChains/Linux.cpp:93
+
+if (TargetTriple.isGNUEnvironment()) {
+  Libc = "gnu";

SixWeining wrote:
> Should only check `{GNU|GNUF32|GNUF64}`?
While technically only `gnu{,sf,f32,f64}` are permitted by the LoongArch 
Toolchain Conventions (with the bare `-gnu` being somewhat de-facto standard 
but not officially so), I believe the user's intent to specify a GNU 
environment still holds even in cases of "errors" like applying "gnuabi64" or 
"gnueabi" to LoongArch. Same applies for the musl case.



Comment at: clang/lib/Driver/ToolChains/Linux.cpp:95
+  Libc = "gnu";
+} else if (TargetTriple.isMusl()) {
+  Libc = "musl";

SixWeining wrote:
> Should only check `Triple::Musl`?
Explained above in the GNU case.



Comment at: clang/lib/Driver/ToolChains/Linux.cpp:116
+
+return std::string("loongarch64-linux-") + Libc + FPFlavor;
+  }

MaskRay wrote:
> `return (... + ...).str();` if an operand of `+` is a `Twine`
Thanks, will change in next revision.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142688/new/

https://reviews.llvm.org/D142688

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


[PATCH] D141785: [Clang][LoongArch] Implement patchable function entry

2023-01-15 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n created this revision.
xen0n added reviewers: SixWeining, wangleiat, gonglingqin, MaskRay, xry111.
Herald added subscribers: luismarques, s.egerton, PkmX, simoncook, hiraditya, 
arichardson.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
xen0n requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead.
Herald added projects: clang, LLVM.

Similar to D98610  for RISCV.

This is going to be required by the upcoming Linux/LoongArch
[[ support for dynamic ftrace | https://git.kernel.org/linus/4733f09d88074 ]].


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141785

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/fpatchable-function-entry.c
  clang/test/Sema/patchable-function-entry-attr.cpp
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
  llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp
  llvm/test/CodeGen/LoongArch/patchable-function-entry.ll

Index: llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
@@ -0,0 +1,62 @@
+;; Test the function attribute "patchable-function-entry".
+; RUN: llc --mtriple=loongarch32 < %s | FileCheck %s --check-prefixes=CHECK,LA32
+; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s --check-prefixes=CHECK,LA64
+
+define void @f0() "patchable-function-entry"="0" {
+; CHECK-LABEL: f0:
+; CHECK-NEXT:  .Lfunc_begin0:
+; CHECK-NOT: nop
+; CHECK: ret
+; CHECK-NOT:   .section __patchable_function_entries
+  ret void
+}
+
+define void @f1() "patchable-function-entry"="1" {
+; CHECK-LABEL: f1:
+; CHECK-NEXT: .Lfunc_begin1:
+; CHECK: nop
+; CHECK-NEXT:ret
+; CHECK:   .section __patchable_function_entries,"awo",@progbits,f1{{$}}
+; LA32:.p2align 2
+; LA32-NEXT:   .word .Lfunc_begin1
+; LA64:.p2align 3
+; LA64-NEXT:   .dword .Lfunc_begin1
+  ret void
+}
+
+$f5 = comdat any
+define void @f5() "patchable-function-entry"="5" comdat {
+; CHECK-LABEL:   f5:
+; CHECK-NEXT:.Lfunc_begin2:
+; CHECK-COUNT-5:   nop
+; CHECK-NEXT:  ret
+; CHECK: .section __patchable_function_entries,"aGwo",@progbits,f5,comdat,f5{{$}}
+; LA32:  .p2align 2
+; LA32-NEXT: .word .Lfunc_begin2
+; LA64:  .p2align 3
+; LA64-NEXT: .dword .Lfunc_begin2
+  ret void
+}
+
+;; -fpatchable-function-entry=3,2
+;; "patchable-function-prefix" emits data before the function entry label.
+define void @f3_2() "patchable-function-entry"="1" "patchable-function-prefix"="2" {
+; CHECK-LABEL:   .type f3_2,@function
+; CHECK-NEXT:.Ltmp0: # @f3_2
+; CHECK-COUNT-2:   nop
+; CHECK-NEXT:f3_2:
+; CHECK: # %bb.0:
+; CHECK-NEXT:  nop
+; LA32-NEXT:   addi.w $sp, $sp, -16
+; LA64-NEXT:   addi.d $sp, $sp, -16
+;; .size does not include the prefix.
+; CHECK:  .Lfunc_end3:
+; CHECK-NEXT: .size f3_2, .Lfunc_end3-f3_2
+; CHECK:  .section __patchable_function_entries,"awo",@progbits,f3_2{{$}}
+; LA32:   .p2align 2
+; LA32-NEXT:  .word .Ltmp0
+; LA64:   .p2align 3
+; LA64-NEXT:  .dword .Ltmp0
+  %frame = alloca i8, i32 16
+  ret void
+}
Index: llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp
===
--- llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp
+++ llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp
@@ -138,5 +138,22 @@
 if (lowerLoongArchMachineOperandToMCOperand(MO, MCOp, AP))
   OutMI.addOperand(MCOp);
   }
+
+  switch (OutMI.getOpcode()) {
+  case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
+const Function &F = MI->getParent()->getParent()->getFunction();
+if (F.hasFnAttribute("patchable-function-entry")) {
+  unsigned Num;
+  if (F.getFnAttribute("patchable-function-entry")
+  .getValueAsString()
+  .getAsInteger(10, Num))
+return false;
+  AP.emitNops(Num);
+  return true;
+}
+break;
+  }
+  }
+
   return false;
 }
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
===
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
@@ -27,6 +27,8 @@
 public:
   explicit LoongArchInstrInfo(LoongArchSubtarget &STI);
 
+  MCInst getNop() const override;
+
   void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
const DebugLoc &DL, MCRegister DstReg, MCRegister SrcReg,
bool KillSrc) const override;
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
===
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
@

[PATCH] D141248: [Clang] [Python] Fix tests when default config file contains -include

2023-01-22 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added inline comments.



Comment at: clang/bindings/python/tests/cindex/util.py:82
+# our tests.
+os.environ["CLANG_NO_DEFAULT_CONFIG"] = "1"
 

This is essentially an import-time side effect, IMO it could be better to 
instead put the envvar provision in 
`clang/bindings/python/tests/CMakeLists.txt`: the `add_custom_target` there 
already is making use of `env` so should be relatively easy to stuff this there 
too.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141248/new/

https://reviews.llvm.org/D141248

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


[PATCH] D154931: [LoongArch] Support InlineAsm for LSX and LASX

2023-07-23 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.

Seems the `u` and `w` modifiers are strictly an implementation detail that's 
different from ordinary inline asm constraints, so even though they take up 
precious single-letter namespace I'd be fine.

Given the architecture-specific nature of the change and usefulness for 
downstream users looking to add SIMD to their programs, I'd be okay with the 
change. Thanks for your contribution.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154931/new/

https://reviews.llvm.org/D154931

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


[PATCH] D156116: [Clang][LoongArch] Fix ABI handling of empty structs in C++ to match GCC behaviour

2023-07-24 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.

So this one is different than D151298  (I'm 
very glad that those registers are ultimately saved btw), and solves a real 
problem. Thanks for the timely catch before LLVM 17 ;-)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156116/new/

https://reviews.llvm.org/D156116

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


[PATCH] D155824: [LoongArch] Support -march=native and -mtune=

2023-07-24 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

In D155824#4530474 , @SixWeining 
wrote:

> @xen0n Do you have any inputs? I think supporting these options can improve 
> compatibility with gcc (although there is no ScheduleModel difference among 
> currently supported processors) and I hope it can be merged into LLVM17.

Sorry for the late reply (busy with rewriting the doc comments for D138135 
). I'm in support of adding those flags, and 
for now I think defaulting to LA464 values would suffice.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155824/new/

https://reviews.llvm.org/D155824

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


[PATCH] D156195: [docs] Add llvm & clang release notes for LoongArch

2023-07-25 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

Thank you (and your team, and of course other friends) for all your work this 
cycle!




Comment at: llvm/docs/ReleaseNotes.rst:202-203
 
+* Adds assembler/disassembler support for the ``LSX``, ``LASX``, ``LVZ`` and
+  ``LBT`` ISA extensions.
 * The ``lp64s`` ABI is supported now and has been tested on Rust bare-matal 
target.

The ISA extension acronyms are not identifiers here, so no need to format as 
inline code?



Comment at: llvm/docs/ReleaseNotes.rst:207
   this feature is enabled by default for generic 64-bit processors.
+* Adds support for the ``large`` code model.
+* Several codegen improvements are made.

I'd suggest mentioning the GCC equivalent, in case people wonder. 
(`-mcmodel=large` is unimplemented GCC-side AFAIK.)



Comment at: llvm/docs/ReleaseNotes.rst:208
+* Adds support for the ``large`` code model.
+* Several codegen improvements are made.
 

"Assorted codegen improvements" sounds more attractive? ;-)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156195/new/

https://reviews.llvm.org/D156195

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


[PATCH] D156195: [docs] Add llvm & clang release notes for LoongArch

2023-07-25 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156195/new/

https://reviews.llvm.org/D156195

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


[PATCH] D155824: [LoongArch] Support -march=native and -mtune=

2023-07-25 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

Overall LGTM except one small nit, thanks!




Comment at: clang/docs/ReleaseNotes.rst:902
   like GCC does.
+- Adds support for the ``-march=native`` and ``-mtune=`` options and the
+  ``__loongarch_{arch,tune}`` pre-defined macros.

"Added"? Or rephrase like "The ... options and ... macros are now supported".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155824/new/

https://reviews.llvm.org/D155824

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


[PATCH] D155824: [LoongArch] Support -march=native and -mtune=

2023-08-03 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp:199-204
+  // Handle CPU name is 'native'.
+  if (CPU == "native") {
+CPU = llvm::sys::getHostCPUName();
+if (CPU == "generic")
+  CPU = llvm::LoongArch::getDefaultArch(Triple.isLoongArch64());
+  }

This part is identical between `-march=` and `-mtune=` handling. I'd suggest 
extracting out a common helper for this, or making this function generic over 
`options::OPT_m*_EQ` (whichever more suitable for you and the Clang 
maintainers; I don't have a particular preference).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155824/new/

https://reviews.llvm.org/D155824

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


[PATCH] D155824: [LoongArch] Support -march=native and -mtune=

2023-08-08 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

This still LGTM, @steven_wu would you please take another look so this can get 
re-landed if confirmed working?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155824/new/

https://reviews.llvm.org/D155824

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


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-07 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added inline comments.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:22-25
+  RN_T0 = 0xC,
+  RN_T1 = 0xD,
+  RN_RA = 0x1,
+  RN_SP = 0x3,

I think people usually just declare the register ABI names with decimal numbers 
for readability?

This is minor but I personally find it slightly distracting to have to think 
about what's `0xc` in decimal (that's the case even though I'm already very 
familiar with these kinds of thing). Not sure if others also prefer decimals 
though...



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:32
+   uint32_t Imm) XRAY_NEVER_INSTRUMENT {
+  return (Opcode | Rj << 5 | Rd | Imm << 10);
+}

Parens not needed in this case. (If you want to enhance readability for those 
people having difficulties remembering precedence and associativeness of 
operators, you should instead put the parens around `Rj << 5` and `Imm << 
10`...)

I'd suggest re-ordering the operands too, to imitate the expected bit layout of 
the result.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:39
+   uint32_t Imm) XRAY_NEVER_INSTRUMENT {
+  return (Opcode | Rd | Imm << 5);
+}

Similarly here.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:42-47
+// Encode instructions in 2RI16 format, e.g. jirl.
+inline static uint32_t
+encodeInstruction2RI16(uint32_t Opcode, uint32_t Rd, uint32_t Rj,
+   uint32_t Imm) XRAY_NEVER_INSTRUMENT {
+  return (Opcode | Rj << 5 | Rd | Imm << 10);
+}

Does this look *very* similar to `encodeInstruction2RI12`? ;-)

Actually, if you don't bounds-check the operands, you only need one helper for 
each combination of slots involved. Check for example the `static uint32_t 
insn` implementation in my D138135, or [[ 
https://gitlab.com/qemu-project/qemu/-/blob/master/tcg/loongarch64/tcg-insn-defs.c.inc
 | the auto-generated encoding helpers for the QEMU TCG LoongArch64 port ]], 
for some alternative approaches.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:58
+  //   11 NOPs (44 bytes)
+  //   .tmpN
+  //

`.tmpN:` for it to not look like a directive?



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:71
+  //   ori t1, t1, %abs_lo12(function_id);pass function id
+  //   jirlra, t0, 0 ;call Tracing hook
+  //   ld.dra, sp, 8 ;restore return address

All-lowercase i.e. `tracing` for consistency? Or am I missing something?



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:73
+  //   ld.dra, sp, 8 ;restore return address
+  //   addi.d  sp, sp, 16;delete stack frame
+  //

I think idiomatically it's not "create/delete stack frame" but rather 
"(de-)allocate" or "setup/teardown"... anyway please fix the usage of articles 
(put the "the"'s properly) and also add a space after the `;` because it's 
usually aesthetically better.

This is all minor though, and it's not like people will misunderstand anything 
otherwise, but rather it's mostly just me pushing for more natural English 
usage.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:80
+  //
+  // When |Enable|==false, we set back the first instruction in the sled to be
+  //   B #48

("set back" happens to be an idiomatic phrase verb so I got confused here for 
~1 second, so I think it's probably easier to just avoid this coincidence.)



Comment at: compiler-rt/lib/xray/xray_trampoline_loongarch64.S:83
+  // a1=1 means that we are tracing an exit event
+  ori $a1, $zero, 1
+  // Function ID is in t1 (the first parameter).

Use pseudo-instruction for idiomatic expression of intent.



Comment at: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp:152-177
+  const int8_t NoopsInSledCount = 11;
+  // For loongarch64 we want to emit the following pattern:
+  //
+  // .Lxray_sled_beginN:
+  //   ALIGN
+  //   B .Lxray_sled_endN
+  //   11 NOP instructions (44 bytes)

We don't have to repeat the instruction pattern when we can just refer people 
to the source file containing this. Also the comment seems to be  explanation 
for the magic number 11, so it should probably come before the definition.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140727/new/

https://reviews.llvm.org/D140727

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


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-11 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

Thanks for following up with the suggestions. This now looks mostly okay to me; 
let's wait for more people to chip in!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140727/new/

https://reviews.llvm.org/D140727

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


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-11 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

Ah, the patch summary probably needs some update as well. We no longer care 
about version 0 and the backend changes for `R_LARCH_64_PCREL` are already in, 
for example.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140727/new/

https://reviews.llvm.org/D140727

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


[PATCH] D138418: [LoongArch] Add remaining intrinsics for CRC check instructions

2022-11-22 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

otherwise LGTM




Comment at: llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp:925
   llvm_unreachable("Unexpected Intrinsic.");
-case Intrinsic::loongarch_crc_w_d_w: {
-  Results.push_back(DAG.getNode(
-  ISD::TRUNCATE, DL, N->getValueType(0),
-  DAG.getNode(
-  LoongArchISD::CRC_W_D_W, DL, MVT::i64, N->getOperand(2),
-  DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(3);
-  Results.push_back(N->getOperand(0));
-  break;
-}
+#define CRC_CASE_EXT_TWOOP(NAME, NODE) 
\
+  case Intrinsic::loongarch_##NAME: {  
\

What's a "two op", are you meaning "binary op" instead?



Comment at: llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp:942
+
+#define CRC_CASE_EXT_ONEOP(NAME, NODE) 
\
+  case Intrinsic::loongarch_##NAME: {  
\

Similarly, is this actually "unary op"?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138418/new/

https://reviews.llvm.org/D138418

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


[PATCH] D139177: [LoongArch] Specify registers used for exception handling

2022-12-02 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

Trivial enough (`$a0` and `$a1` respectively, same as RISCV and Mips). Thanks 
for the quick fixing!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139177/new/

https://reviews.llvm.org/D139177

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


[PATCH] D152671: [doc][LoongArch] Add missed release note about `ual` feature addition

2023-06-21 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

Thanks for the catch!




Comment at: llvm/docs/ReleaseNotes.rst:163
 * The ``lp64s`` ABI is supported now and has been tested on Rust bare-matal 
target.
+* An target feature ``ual`` is introduced to allow unaligned memory accesses 
and
+  this feature is enabled by default on generic 64bit processors.

nit: "A" (the following sound is not a vowel)



Comment at: llvm/docs/ReleaseNotes.rst:164
+* An target feature ``ual`` is introduced to allow unaligned memory accesses 
and
+  this feature is enabled by default on generic 64bit processors.
 

nit: "for generic 64-bit"

Here "for" (compared to "on") is to signify it's controlled by target instead 
of host spec.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152671/new/

https://reviews.llvm.org/D152671

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


[PATCH] D153707: [Clang][LoongArch] Consume and check -mabi and -mfpu even if -m*-float is present

2023-06-24 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n created this revision.
xen0n added reviewers: SixWeining, wangleiat, hev, xry111, MaskRay.
Herald added a subscriber: tpr.
Herald added a project: All.
xen0n requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This kind of CLI flags duplication can sometimes be convenient for build
systems that may have to tinker with these.

For example, in the Linux kernel we almost always want to ensure no FP
instruction is emitted, so `-msoft-float` is present by default; but
sometimes we do want to allow FPU usage (e.g. certain parts of amdgpu DC
code), in which case we want the `-msoft-float` stripped and `-mfpu=64`
added. Here we face a dilemma without this change:

- Either `-mabi` is not supplied by `arch/loongarch` Makefile, in which case 
the correct ABI has to be supplied by the driver Makefile, potentially 
duplicating logic;
- Or `-mabi` is still supplied by `arch/loongarch` Makefile, and the build 
immediately errors out because `-Werror,-Wunused-command-line-argument` is 
unconditionally set for Clang builds.

To solve this, simply make sure to check `-mabi` and `-mfpu` (and gain
some useful diagnostics in case of conflicting settings) when
`-m*-float` is successfully parsed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153707

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/test/Driver/loongarch-mdouble-float.c
  clang/test/Driver/loongarch-msingle-float.c
  clang/test/Driver/loongarch-msoft-float.c

Index: clang/test/Driver/loongarch-msoft-float.c
===
--- clang/test/Driver/loongarch-msoft-float.c
+++ clang/test/Driver/loongarch-msoft-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -msoft-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msoft-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msoft-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msoft-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=64'
-// WARN: warning: argument unused during compilation: '-mabi=lp64d'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=0'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64s'
+// WARN: warning: the -mabi setting 'lp64d' conflicts with that implied by -m*-float (lp64s); using lp64s
+// WARN: warning: the -mfpu setting '64' conflicts with that implied by -m*-float (0); using 0
 
 // CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64s"
Index: clang/test/Driver/loongarch-msingle-float.c
===
--- clang/test/Driver/loongarch-msingle-float.c
+++ clang/test/Driver/loongarch-msingle-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -msingle-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msingle-float -mfpu=32 -mabi=lp64f -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msingle-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msingle-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=32'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64f'
+// WARN: warning: the -mabi setting 'lp64s' conflicts with that implied by -m*-float (lp64f); using lp64f
+// WARN: warning: the -mfpu setting '0' conflicts with that implied by -m*-float (32); using 32
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64f"
Index: clang/test/Driver/loongarch-mdouble-float.c
===
--- clang/test/Driver/loongarch-mdouble-float.c
+++ clang/test/Driver/loongarch-mdouble-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -mdouble-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -mdouble-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -mdouble-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongar

[PATCH] D153707: [Clang][LoongArch] Consume and check -mabi and -mfpu even if -m*-float is present

2023-06-24 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n updated this revision to Diff 534241.
xen0n added a comment.

Fix faulty refactor (unintended always-error case).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153707/new/

https://reviews.llvm.org/D153707

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/test/Driver/loongarch-mdouble-float.c
  clang/test/Driver/loongarch-msingle-float.c
  clang/test/Driver/loongarch-msoft-float.c

Index: clang/test/Driver/loongarch-msoft-float.c
===
--- clang/test/Driver/loongarch-msoft-float.c
+++ clang/test/Driver/loongarch-msoft-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -msoft-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msoft-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msoft-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msoft-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=64'
-// WARN: warning: argument unused during compilation: '-mabi=lp64d'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=0'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64s'
+// WARN: warning: the -mabi setting 'lp64d' conflicts with that implied by -m*-float (lp64s); using lp64s
+// WARN: warning: the -mfpu setting '64' conflicts with that implied by -m*-float (0); using 0
 
 // CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64s"
Index: clang/test/Driver/loongarch-msingle-float.c
===
--- clang/test/Driver/loongarch-msingle-float.c
+++ clang/test/Driver/loongarch-msingle-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -msingle-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msingle-float -mfpu=32 -mabi=lp64f -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msingle-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msingle-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=32'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64f'
+// WARN: warning: the -mabi setting 'lp64s' conflicts with that implied by -m*-float (lp64f); using lp64f
+// WARN: warning: the -mfpu setting '0' conflicts with that implied by -m*-float (32); using 32
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64f"
Index: clang/test/Driver/loongarch-mdouble-float.c
===
--- clang/test/Driver/loongarch-mdouble-float.c
+++ clang/test/Driver/loongarch-mdouble-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -mdouble-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -mdouble-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -mdouble-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -mdouble-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=64'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64d'
+// WARN: warning: the -mabi setting 'lp64s' conflicts with that implied by -m*-float (lp64d); using lp64d
+// WARN: warning: the -mfpu setting '0' conflicts with that implied by -m*-float (64); using 64
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "+d"
 // CC1: "-target-abi" "lp64d"
Index: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
===
--- clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -26,16 +26,55 @@
  "Unexpected triple");
   bool IsLA32 = Triple.getArch() == llvm::Triple::loongarch32;
 
+  // Parse -mfpu value for later use.
+  int FPU = -1;
+

[PATCH] D153707: [Clang][LoongArch] Consume and check -mabi and -mfpu even if -m*-float is present

2023-06-25 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n updated this revision to Diff 534325.
xen0n added a comment.

Refactored to reduce duplication of flag processing logic and save one level of 
indent.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153707/new/

https://reviews.llvm.org/D153707

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/test/Driver/loongarch-mdouble-float.c
  clang/test/Driver/loongarch-msingle-float.c
  clang/test/Driver/loongarch-msoft-float.c

Index: clang/test/Driver/loongarch-msoft-float.c
===
--- clang/test/Driver/loongarch-msoft-float.c
+++ clang/test/Driver/loongarch-msoft-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -msoft-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msoft-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msoft-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msoft-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=64'
-// WARN: warning: argument unused during compilation: '-mabi=lp64d'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=0'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64s'
+// WARN: warning: the -mabi setting 'lp64d' conflicts with that implied by -m*-float (lp64s); using lp64s
+// WARN: warning: the -mfpu setting '64' conflicts with that implied by -m*-float (0); using 0
 
 // CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64s"
Index: clang/test/Driver/loongarch-msingle-float.c
===
--- clang/test/Driver/loongarch-msingle-float.c
+++ clang/test/Driver/loongarch-msingle-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -msingle-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msingle-float -mfpu=32 -mabi=lp64f -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msingle-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msingle-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=32'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64f'
+// WARN: warning: the -mabi setting 'lp64s' conflicts with that implied by -m*-float (lp64f); using lp64f
+// WARN: warning: the -mfpu setting '0' conflicts with that implied by -m*-float (32); using 32
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64f"
Index: clang/test/Driver/loongarch-mdouble-float.c
===
--- clang/test/Driver/loongarch-mdouble-float.c
+++ clang/test/Driver/loongarch-mdouble-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -mdouble-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -mdouble-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -mdouble-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -mdouble-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=64'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64d'
+// WARN: warning: the -mabi setting 'lp64s' conflicts with that implied by -m*-float (lp64d); using lp64d
+// WARN: warning: the -mfpu setting '0' conflicts with that implied by -m*-float (64); using 64
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "+d"
 // CC1: "-target-abi" "lp64d"
Index: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
===
--- clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -26,32 +26,71 @@
  "Unexpected triple");
   bool IsLA32 = Triple.getArch() == llvm::Triple::loongarch32;
 
+  // Record -mabi v

[PATCH] D153707: [Clang][LoongArch] Consume and check -mabi and -mfpu even if -m*-float is present

2023-06-25 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp:64
+// conflicts with the higher-priority settings implied by -m*-float.
+if (!ImpliedABI.empty()) {
+  if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {

SixWeining wrote:
> Seems that this condition is always `true`.
Yes you're right. I'll simplify it (and add comment detailing why it's safe to 
assume non-emptiness) shortly.



Comment at: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp:85
   // Select abi based on -mfpu=xx.
-  if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) {
-StringRef FPU = A->getValue();
-if (FPU == "64")
-  return IsLA32 ? "ilp32d" : "lp64d";
-if (FPU == "32")
-  return IsLA32 ? "ilp32f" : "lp64f";
-if (FPU == "0" || FPU == "none")
-  return IsLA32 ? "ilp32s" : "lp64s";
-D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) << FPU;
+  switch (FPU) {
+  case 64:

SixWeining wrote:
> Without `default`, there may be compiling warning?
I didn't remember seeing such warnings; plus the case's body would be empty 
anyway...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153707/new/

https://reviews.llvm.org/D153707

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


[PATCH] D153707: [Clang][LoongArch] Consume and check -mabi and -mfpu even if -m*-float is present

2023-06-25 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n updated this revision to Diff 534326.
xen0n marked an inline comment as done.
xen0n added a comment.

Grammatical fix of comment text ("is" -> "are").


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153707/new/

https://reviews.llvm.org/D153707

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/test/Driver/loongarch-mdouble-float.c
  clang/test/Driver/loongarch-msingle-float.c
  clang/test/Driver/loongarch-msoft-float.c

Index: clang/test/Driver/loongarch-msoft-float.c
===
--- clang/test/Driver/loongarch-msoft-float.c
+++ clang/test/Driver/loongarch-msoft-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -msoft-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msoft-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msoft-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msoft-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=64'
-// WARN: warning: argument unused during compilation: '-mabi=lp64d'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=0'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64s'
+// WARN: warning: the -mabi setting 'lp64d' conflicts with that implied by -m*-float (lp64s); using lp64s
+// WARN: warning: the -mfpu setting '64' conflicts with that implied by -m*-float (0); using 0
 
 // CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64s"
Index: clang/test/Driver/loongarch-msingle-float.c
===
--- clang/test/Driver/loongarch-msingle-float.c
+++ clang/test/Driver/loongarch-msingle-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -msingle-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msingle-float -mfpu=32 -mabi=lp64f -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msingle-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msingle-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=32'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64f'
+// WARN: warning: the -mabi setting 'lp64s' conflicts with that implied by -m*-float (lp64f); using lp64f
+// WARN: warning: the -mfpu setting '0' conflicts with that implied by -m*-float (32); using 32
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64f"
Index: clang/test/Driver/loongarch-mdouble-float.c
===
--- clang/test/Driver/loongarch-mdouble-float.c
+++ clang/test/Driver/loongarch-mdouble-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -mdouble-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -mdouble-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -mdouble-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -mdouble-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=64'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64d'
+// WARN: warning: the -mabi setting 'lp64s' conflicts with that implied by -m*-float (lp64d); using lp64d
+// WARN: warning: the -mfpu setting '0' conflicts with that implied by -m*-float (64); using 64
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "+d"
 // CC1: "-target-abi" "lp64d"
Index: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
===
--- clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -26,32 +26,71 @@
  "Unexpected triple");
   bool IsLA32 = Triple.getArch() == llvm::Triple::loongarch32;
 
+  // Record -mabi v

[PATCH] D153707: [Clang][LoongArch] Consume and check -mabi and -mfpu even if -m*-float is present

2023-06-25 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n updated this revision to Diff 534365.
xen0n added a comment.

Address @MaskRay's review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153707/new/

https://reviews.llvm.org/D153707

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/test/Driver/loongarch-mdouble-float.c
  clang/test/Driver/loongarch-msingle-float.c
  clang/test/Driver/loongarch-msoft-float.c

Index: clang/test/Driver/loongarch-msoft-float.c
===
--- clang/test/Driver/loongarch-msoft-float.c
+++ clang/test/Driver/loongarch-msoft-float.c
@@ -1,12 +1,15 @@
 // RUN: %clang --target=loongarch64 -msoft-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msoft-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msoft-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msoft-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=64'
-// WARN: warning: argument unused during compilation: '-mabi=lp64d'
+// NOWARN-NOT: warning:
+// WARN: warning: ignoring -mabi value 'lp64d' as it conflicts with that implied by -m*-float (lp64s)
+// WARN: warning: ignoring -mfpu value '64' as it conflicts with that implied by -m*-float (0)
 
 // CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64s"
Index: clang/test/Driver/loongarch-msingle-float.c
===
--- clang/test/Driver/loongarch-msingle-float.c
+++ clang/test/Driver/loongarch-msingle-float.c
@@ -1,12 +1,15 @@
 // RUN: %clang --target=loongarch64 -msingle-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msingle-float -mfpu=32 -mabi=lp64f -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msingle-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msingle-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning:
+// WARN: warning: ignoring -mabi value 'lp64s' as it conflicts with that implied by -m*-float (lp64f)
+// WARN: warning: ignoring -mfpu value '0' as it conflicts with that implied by -m*-float (32)
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64f"
Index: clang/test/Driver/loongarch-mdouble-float.c
===
--- clang/test/Driver/loongarch-mdouble-float.c
+++ clang/test/Driver/loongarch-mdouble-float.c
@@ -1,12 +1,15 @@
 // RUN: %clang --target=loongarch64 -mdouble-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -mdouble-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -mdouble-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -mdouble-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning:
+// WARN: warning: ignoring -mabi value 'lp64s' as it conflicts with that implied by -m*-float (lp64d)
+// WARN: warning: ignoring -mfpu value '0' as it conflicts with that implied by -m*-float (64)
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "+d"
 // CC1: "-target-abi" "lp64d"
Index: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
===
--- clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -26,32 +26,71 @@
  "Unexpected triple");
   bool IsLA32 = Triple.getArch() == llvm::Triple::loongarch32;
 
+  // Record -mabi value for later use.
+  StringRef MABIValue;
+  if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
+MABIValue = A->getValue();
+
+  // Parse -mfpu value for later use.
+  int FPU = -1;
+  if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) {
+StringRef V = A->getValue();
+if (V == "64")
+  FPU = 64;
+else if (V == "32")
+  FPU = 32;
+else if (V == "0" || V == "none")
+  FPU = 0;
+e

[PATCH] D153707: [Clang][LoongArch] Consume and check -mabi and -mfpu even if -m*-float is present

2023-06-25 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n marked 2 inline comments as done.
xen0n added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:732
+def warn_drv_loongarch_conflicting_mabi : Warning<
+  "the -mabi setting '%0' conflicts with that implied by -m*-float (%1); using 
%1">,
+  InGroup;

MaskRay wrote:
> This is not called `setting`. Use `value`
> 
> It seems that `ignoring -mabi value '%0' as it conflicts ...` is more 
> conventional.
Sounds reasonable. I've checked other similar diagnostics text and it seems 
your suggestion is stylistically more consistent.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153707/new/

https://reviews.llvm.org/D153707

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


[PATCH] D153707: [Clang][LoongArch] Consume and check -mabi and -mfpu even if -m*-float is present

2023-06-25 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n updated this revision to Diff 534427.
xen0n marked an inline comment as done.
xen0n added a comment.

Unify the diagnostic messages and show the actual `-m*-float` option being 
passed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153707/new/

https://reviews.llvm.org/D153707

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/test/Driver/loongarch-mdouble-float.c
  clang/test/Driver/loongarch-msingle-float.c
  clang/test/Driver/loongarch-msoft-float.c

Index: clang/test/Driver/loongarch-msoft-float.c
===
--- clang/test/Driver/loongarch-msoft-float.c
+++ clang/test/Driver/loongarch-msoft-float.c
@@ -1,12 +1,15 @@
 // RUN: %clang --target=loongarch64 -msoft-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msoft-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msoft-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msoft-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=64'
-// WARN: warning: argument unused during compilation: '-mabi=lp64d'
+// NOWARN-NOT: warning:
+// WARN: warning: ignoring '-mabi=' value 'lp64d' as it conflicts with that implied by '-msoft-float' (lp64s)
+// WARN: warning: ignoring '-mfpu=' value '64' as it conflicts with that implied by '-msoft-float' (0)
 
 // CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64s"
Index: clang/test/Driver/loongarch-msingle-float.c
===
--- clang/test/Driver/loongarch-msingle-float.c
+++ clang/test/Driver/loongarch-msingle-float.c
@@ -1,12 +1,15 @@
 // RUN: %clang --target=loongarch64 -msingle-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msingle-float -mfpu=32 -mabi=lp64f -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msingle-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msingle-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning:
+// WARN: warning: ignoring '-mabi=' value 'lp64s' as it conflicts with that implied by '-msingle-float' (lp64f)
+// WARN: warning: ignoring '-mfpu=' value '0' as it conflicts with that implied by '-msingle-float' (32)
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64f"
Index: clang/test/Driver/loongarch-mdouble-float.c
===
--- clang/test/Driver/loongarch-mdouble-float.c
+++ clang/test/Driver/loongarch-mdouble-float.c
@@ -1,12 +1,15 @@
 // RUN: %clang --target=loongarch64 -mdouble-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -mdouble-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -mdouble-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -mdouble-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning:
+// WARN: warning: ignoring '-mabi=' value 'lp64s' as it conflicts with that implied by '-mdouble-float' (lp64d)
+// WARN: warning: ignoring '-mfpu=' value '0' as it conflicts with that implied by '-mdouble-float' (64)
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "+d"
 // CC1: "-target-abi" "lp64d"
Index: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
===
--- clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -26,32 +26,80 @@
  "Unexpected triple");
   bool IsLA32 = Triple.getArch() == llvm::Triple::loongarch32;
 
+  // Record -mabi value for later use.
+  std::optional MABIOption;
+  StringRef MABIValue;
+  if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
+MABIOption = A->getOption();
+MABIValue = A->getValue();
+  }
+
+  // Parse -mfpu value for later use.
+  std::optional MFPUOption;
+  int FPU 

[PATCH] D153707: [Clang][LoongArch] Consume and check -mabi and -mfpu even if -m*-float is present

2023-06-25 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n updated this revision to Diff 534430.
xen0n added a comment.

Refactor more to be able to show the exact `-mabi` and `-mfpu` argument given.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153707/new/

https://reviews.llvm.org/D153707

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/test/Driver/loongarch-mdouble-float.c
  clang/test/Driver/loongarch-msingle-float.c
  clang/test/Driver/loongarch-msoft-float.c

Index: clang/test/Driver/loongarch-msoft-float.c
===
--- clang/test/Driver/loongarch-msoft-float.c
+++ clang/test/Driver/loongarch-msoft-float.c
@@ -1,12 +1,15 @@
 // RUN: %clang --target=loongarch64 -msoft-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msoft-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msoft-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msoft-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=64'
-// WARN: warning: argument unused during compilation: '-mabi=lp64d'
+// NOWARN-NOT: warning:
+// WARN: warning: ignoring '-mabi=lp64d' as it conflicts with that implied by '-msoft-float' (lp64s)
+// WARN: warning: ignoring '-mfpu=64' as it conflicts with that implied by '-msoft-float' (0)
 
 // CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64s"
Index: clang/test/Driver/loongarch-msingle-float.c
===
--- clang/test/Driver/loongarch-msingle-float.c
+++ clang/test/Driver/loongarch-msingle-float.c
@@ -1,12 +1,15 @@
 // RUN: %clang --target=loongarch64 -msingle-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
-// RUN: %clang --target=loongarch64 -msingle-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
+// RUN: %clang --target=loongarch64 -msingle-float -mfpu=32 -mabi=lp64f -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
+// RUN: %clang --target=loongarch64 -msingle-float -mfpu=64 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msingle-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning:
+// WARN: warning: ignoring '-mabi=lp64s' as it conflicts with that implied by '-msingle-float' (lp64f)
+// WARN: warning: ignoring '-mfpu=64' as it conflicts with that implied by '-msingle-float' (32)
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64f"
Index: clang/test/Driver/loongarch-mdouble-float.c
===
--- clang/test/Driver/loongarch-mdouble-float.c
+++ clang/test/Driver/loongarch-mdouble-float.c
@@ -1,12 +1,18 @@
 // RUN: %clang --target=loongarch64 -mdouble-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -mdouble-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -mdouble-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
-// RUN:   FileCheck %s --check-prefixes=CC1,WARN
+// RUN:   FileCheck %s --check-prefixes=CC1,WARN,WARN-FPU0
+// RUN: %clang --target=loongarch64 -mdouble-float -mfpu=none -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,WARN,WARN-FPUNONE
 // RUN: %clang --target=loongarch64 -mdouble-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning:
+// WARN: warning: ignoring '-mabi=lp64s' as it conflicts with that implied by '-mdouble-float' (lp64d)
+// WARN-FPU0: warning: ignoring '-mfpu=0' as it conflicts with that implied by '-mdouble-float' (64)
+// WARN-FPUNONE: warning: ignoring '-mfpu=none' as it conflicts with that implied by '-mdouble-float' (64)
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "+d"
 // CC1: "-target-abi" "lp64d"
Index: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
===
--- clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -26,32 +26,75 @@
  "Unexpected triple");
   bool IsLA32 = Triple.ge

[PATCH] D142688: [Clang][Driver] Handle LoongArch multiarch tuples

2023-04-02 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n updated this revision to Diff 510320.
xen0n added a comment.

Rebase and reflect the Toolchain Conventions change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142688/new/

https://reviews.llvm.org/D142688

Files:
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/loongarch-abi.c

Index: clang/test/Driver/loongarch-abi.c
===
--- clang/test/Driver/loongarch-abi.c
+++ clang/test/Driver/loongarch-abi.c
@@ -16,6 +16,34 @@
 // RUN: %clang --target=loongarch64-unknown-elf %s -fsyntax-only -### -mabi=lp64d 2>&1 \
 // RUN:   | FileCheck --check-prefix=LP64D %s
 
+// RUN: %clang --target=loongarch32-linux-gnusf %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32S %s
+// RUN: %clang --target=loongarch32-linux-gnuf32 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32F %s
+// RUN: %clang --target=loongarch32-linux-gnuf64 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32D %s
+// RUN: %clang --target=loongarch32-linux-gnu %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32D %s
+
+// RUN: %clang --target=loongarch64-linux-gnusf %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64S %s
+// RUN: %clang --target=loongarch64-linux-gnuf32 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64F %s
+// RUN: %clang --target=loongarch64-linux-gnuf64 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64D %s
+// RUN: %clang --target=loongarch64-linux-gnu %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64D %s
+
+// Check that -mabi prevails in case of conflicts with the triple-implied ABI.
+// RUN: %clang --target=loongarch32-linux-gnuf64 %s -fsyntax-only -### -mabi=ilp32s 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32S %s
+// RUN: %clang --target=loongarch64-linux-gnuf64 %s -fsyntax-only -### -mabi=lp64s 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64S %s
+// RUN: %clang --target=loongarch32-linux-gnu %s -fsyntax-only -### -mabi=ilp32s 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32S %s
+// RUN: %clang --target=loongarch64-linux-gnu %s -fsyntax-only -### -mabi=lp64s 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64S %s
+
 // ILP32S: "-target-abi" "ilp32s"
 // ILP32F: "-target-abi" "ilp32f"
 // ILP32D: "-target-abi" "ilp32d"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -86,6 +86,39 @@
   case llvm::Triple::aarch64_be:
 return "aarch64_be-linux-gnu";
 
+  case llvm::Triple::loongarch64: {
+const char *Libc;
+const char *FPFlavor;
+
+if (TargetTriple.isGNUEnvironment()) {
+  Libc = "gnu";
+} else if (TargetTriple.isMusl()) {
+  Libc = "musl";
+} else {
+  return TargetTriple.str();
+}
+
+switch (TargetEnvironment) {
+default:
+  return TargetTriple.str();
+case llvm::Triple::GNUSF:
+  FPFlavor = "sf";
+  break;
+case llvm::Triple::GNUF32:
+  FPFlavor = "f32";
+  break;
+case llvm::Triple::GNU:
+case llvm::Triple::GNUF64:
+  // This was going to be "f64" in an earlier Toolchain Conventions
+  // revision, but starting from Feb 2023 the F64 ABI variants are
+  // unmarked in their canonical forms.
+  FPFlavor = "";
+  break;
+}
+
+return std::string("loongarch64-linux-") + Libc + FPFlavor;
+  }
+
   case llvm::Triple::m68k:
 return "m68k-linux-gnu";
 
Index: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
===
--- clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -54,7 +54,28 @@
   }
 
   // Choose a default based on the triple.
-  return IsLA32 ? "ilp32d" : "lp64d";
+  // Honor the explicit ABI modifier suffix in triple's environment part if
+  // present, falling back to {ILP32,LP64}D otherwise.
+  switch (Triple.getEnvironment()) {
+  case llvm::Triple::GNUSF:
+return IsLA32 ? "ilp32s" : "lp64s";
+  case llvm::Triple::GNUF32:
+return IsLA32 ? "ilp32f" : "lp64f";
+  case llvm::Triple::GNUF64:
+// This was originally permitted (and indeed the canonical way) to
+// represent the {ILP32,LP64}D ABIs, but in Feb 2023 Loongson decided to
+// drop the explicit suffix in favor of unmarked `-gnu` for the
+// "general-purpose" ABIs, among other non-technical reasons.
+//
+// The spec change did not mention whether existing usages of "gnuf64"
+// shall remain valid or not, so we are going to continue recognizing it
+// for some time, until it is clear that everyone else has migrated away
+// from it.
+[[fallthrough]];
+  case llvm::Triple::GNU:
+  default:
+return IsLA32 ? "il

[PATCH] D142688: [Clang][Driver] Handle LoongArch multiarch tuples

2023-04-02 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n marked 5 inline comments as done.
xen0n added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp:66
+  default:
+return IsLA32 ? "ilp32d" : "lp64d";
+  }

xry111 wrote:
> SixWeining wrote:
> > Better to be `f`? (Probably most 32-bit hardwares do not support 
> > double-float? But I'm not sure about this.)
> The ISA manual says 64-bit float support is not limited by 32-bit basic ISA 
> support (except the moving instructions accessing 64-bit GPR).
AFAIK the consensus (even inside Loongson) is that even LA32's unmarked/default 
ABI is going to have hard F64 available. And yes the ISA manual is consistent 
with this view too. (IMO LA32 should instead default to soft-float, but if 
Loongson's commercial roadmap can guarantee hardware FPU availability on all 
meaningful LA32 models then that would backfire, who knows...)



Comment at: clang/lib/Driver/ToolChains/Linux.cpp:41
 /// so we provide a rough mapping here.
 std::string Linux::getMultiarchTriple(const Driver &D,
   const llvm::Triple &TargetTriple,

SixWeining wrote:
> xen0n wrote:
> > SixWeining wrote:
> > > Missing test. Perhaps add some in `clang/test/Driver/linux-ld.c` and 
> > > `clang/test/Driver/linux-header-search.cpp`? Or postpone this change 
> > > until loongarch is upstreamed to Debian?
> > Thanks, I'll try adding the tests in the next revision.
> > 
> > But given [[ https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1028654 | 
> > the recent reversal of upstream dpkg support ]] (apparently due to 
> > miscommunication) it may be prudent to wait until a consensus is reached 
> > Debian-side.
> [[ https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=9dfffbbae | The 
> multiarch tuples have been upstreamed to dpkg ]].  I think we can amend the 
> change and move on now.
Sorry for the delay in processing this, I've updated the code to reflect the 
latest spec change. I'll still have to check the unit-test part though.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142688/new/

https://reviews.llvm.org/D142688

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


[PATCH] D142688: [Clang][Driver] Handle LoongArch multiarch tuples

2023-04-02 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n updated this revision to Diff 510333.
xen0n marked an inline comment as done.
xen0n added a comment.

Rebase and add tests, also use Twine for concatenating strings


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142688/new/

https://reviews.llvm.org/D142688

Files:
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/Inputs/debian_loong64_tree/usr/include/c++/13/backward/.keep
  
clang/test/Driver/Inputs/debian_loong64_tree/usr/include/loongarch64-linux-gnu/c++/.keep
  
clang/test/Driver/Inputs/debian_loong64_tree/usr/lib/gcc/loongarch64-linux-gnu/13/crtbegin.o
  
clang/test/Driver/Inputs/debian_loong64_tree/usr/lib/gcc/loongarch64-linux-gnu/13/crtend.o
  
clang/test/Driver/Inputs/debian_loong64_tree/usr/lib/gcc/loongarch64-linux-gnu/13/include/.keep
  
clang/test/Driver/Inputs/debian_loong64_tree/usr/lib/loongarch64-linux-gnu/crt1.o
  
clang/test/Driver/Inputs/debian_loong64_tree/usr/lib/loongarch64-linux-gnu/crti.o
  
clang/test/Driver/Inputs/debian_loong64_tree/usr/lib/loongarch64-linux-gnu/crtn.o
  clang/test/Driver/linux-header-search.cpp
  clang/test/Driver/linux-ld.c
  clang/test/Driver/loongarch-abi.c

Index: clang/test/Driver/loongarch-abi.c
===
--- clang/test/Driver/loongarch-abi.c
+++ clang/test/Driver/loongarch-abi.c
@@ -16,6 +16,34 @@
 // RUN: %clang --target=loongarch64-unknown-elf %s -fsyntax-only -### -mabi=lp64d 2>&1 \
 // RUN:   | FileCheck --check-prefix=LP64D %s
 
+// RUN: %clang --target=loongarch32-linux-gnusf %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32S %s
+// RUN: %clang --target=loongarch32-linux-gnuf32 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32F %s
+// RUN: %clang --target=loongarch32-linux-gnuf64 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32D %s
+// RUN: %clang --target=loongarch32-linux-gnu %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32D %s
+
+// RUN: %clang --target=loongarch64-linux-gnusf %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64S %s
+// RUN: %clang --target=loongarch64-linux-gnuf32 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64F %s
+// RUN: %clang --target=loongarch64-linux-gnuf64 %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64D %s
+// RUN: %clang --target=loongarch64-linux-gnu %s -fsyntax-only -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64D %s
+
+// Check that -mabi prevails in case of conflicts with the triple-implied ABI.
+// RUN: %clang --target=loongarch32-linux-gnuf64 %s -fsyntax-only -### -mabi=ilp32s 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32S %s
+// RUN: %clang --target=loongarch64-linux-gnuf64 %s -fsyntax-only -### -mabi=lp64s 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64S %s
+// RUN: %clang --target=loongarch32-linux-gnu %s -fsyntax-only -### -mabi=ilp32s 2>&1 \
+// RUN:   | FileCheck --check-prefix=ILP32S %s
+// RUN: %clang --target=loongarch64-linux-gnu %s -fsyntax-only -### -mabi=lp64s 2>&1 \
+// RUN:   | FileCheck --check-prefix=LP64S %s
+
 // ILP32S: "-target-abi" "ilp32s"
 // ILP32F: "-target-abi" "ilp32f"
 // ILP32D: "-target-abi" "ilp32d"
Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -830,6 +830,30 @@
 // CHECK-ARM-HF: "-dynamic-linker" "{{.*}}/lib/ld-linux-armhf.so.3"
 //
 // RUN: %clang -### %s -no-pie 2>&1 \
+// RUN: --target=loongarch64-linux-gnu \
+// RUN:   | FileCheck --check-prefix=CHECK-LOONGARCH-LP64D %s
+// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN: --target=loongarch64-linux-gnuf64 \
+// RUN:   | FileCheck --check-prefix=CHECK-LOONGARCH-LP64D %s
+// CHECK-LOONGARCH-LP64D: "{{.*}}ld{{(.exe)?}}"
+// CHECK-LOONGARCH-LP64D: "-m" "elf64loongarch"
+// CHECK-LOONGARCH-LP64D: "-dynamic-linker" "{{.*}}/lib64/ld-linux-loongarch-lp64d.so.1"
+//
+// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN: --target=loongarch64-linux-gnuf32 \
+// RUN:   | FileCheck --check-prefix=CHECK-LOONGARCH-LP64F %s
+// CHECK-LOONGARCH-LP64F: "{{.*}}ld{{(.exe)?}}"
+// CHECK-LOONGARCH-LP64F: "-m" "elf64loongarch"
+// CHECK-LOONGARCH-LP64F: "-dynamic-linker" "{{.*}}/lib64/ld-linux-loongarch-lp64f.so.1"
+//
+// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN: --target=loongarch64-linux-gnusf \
+// RUN:   | FileCheck --check-prefix=CHECK-LOONGARCH-LP64S %s
+// CHECK-LOONGARCH-LP64S: "{{.*}}ld{{(.exe)?}}"
+// CHECK-LOONGARCH-LP64S: "-m" "elf64loongarch"
+// CHECK-LOONGARCH-LP64S: "-dynamic-linker" "{{.*}}/lib64/ld-linux-loongarch-lp64s.so.1"
+//
+// RUN: %clang -### %s -no-pie 2>&1 \
 // RUN: --target=powerpc64-linux-gnu \
 // RUN:   | FileCheck --check-prefix=CHECK-PPC64 %s
 // CHECK-PPC64: "{{.*}}ld{{(.exe)?}}"
@@ -1311,6 +1335,29 @@
 // RUN:   | FileCheck --check-pref

[PATCH] D142688: [Clang][Driver] Handle LoongArch multiarch tuples

2023-04-02 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n marked 2 inline comments as done.
xen0n added inline comments.



Comment at: clang/lib/Driver/ToolChains/Linux.cpp:41
 /// so we provide a rough mapping here.
 std::string Linux::getMultiarchTriple(const Driver &D,
   const llvm::Triple &TargetTriple,

xen0n wrote:
> SixWeining wrote:
> > xen0n wrote:
> > > SixWeining wrote:
> > > > Missing test. Perhaps add some in `clang/test/Driver/linux-ld.c` and 
> > > > `clang/test/Driver/linux-header-search.cpp`? Or postpone this change 
> > > > until loongarch is upstreamed to Debian?
> > > Thanks, I'll try adding the tests in the next revision.
> > > 
> > > But given [[ https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1028654 | 
> > > the recent reversal of upstream dpkg support ]] (apparently due to 
> > > miscommunication) it may be prudent to wait until a consensus is reached 
> > > Debian-side.
> > [[ https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=9dfffbbae | The 
> > multiarch tuples have been upstreamed to dpkg ]].  I think we can amend the 
> > change and move on now.
> Sorry for the delay in processing this, I've updated the code to reflect the 
> latest spec change. I'll still have to check the unit-test part though.
I've now added tests for the Debian sysroot layout, based on Revy's latest work.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142688/new/

https://reviews.llvm.org/D142688

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


[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-05-24 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

FYI, in the matching GCC patch discussion 
 it was 
suggested that such a treatment wouldn't be necessary in principle.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151298/new/

https://reviews.llvm.org/D151298

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


[PATCH] D149946: [LoongArch] Define `ual` feature and override `allowsMisalignedMemoryAccesses`

2023-06-02 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

I've thought about this a bit harder; it now seems better longer-term to enable 
unaligned accesses by default (making the UAL-less models the special case).

But most importantly, there's new information suggesting that UAL support is to 
become ubiquitous in the future. A sample `/proc/cpuinfo` output on a Loongson 
2K2000 (LA364 uarch) recently is circulated in various user groups 
(unfortunately there doesn't seem to be a public link), that clearly shows 
LA364 has UAL. So this very likely means all future Loongson-2 series will 
feature UAL, and that the non-UAL case is to gradually become less relevant.

Also, in some cases (distro packaging, mesa llvmpipe, etc.) it may not be as 
easy to specify `march` flags, but we may want to assume a more popular model 
nevertheless. Again the UAL-less models should be seen as special cases and get 
adapted individually later.

With the reasoning becoming clear, the LoongArch target part of the change 
LGTM; thanks for taking care of this!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149946/new/

https://reviews.llvm.org/D149946

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


[PATCH] D141785: [Clang][LoongArch] Implement patchable function entry

2023-02-06 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added inline comments.



Comment at: llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp:150
+  .getAsInteger(10, Num))
+return false;
+  AP.emitNops(Num);

SixWeining wrote:
> Seems should return `true`? Consider when verifier is disabled.
> 
> How about handling `PATCHABLE_FUNCTION_ENTER` in `LoongArchAsmPrinter.cpp` 
> like D140727?
I've checked other targets and indeed implementation in `AsmPrinter` is the 
more widespread approach (RISCV is the outlier here). Let me adjust in one or 
two days.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141785/new/

https://reviews.llvm.org/D141785

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


[PATCH] D141785: [Clang][LoongArch] Implement patchable function entry

2023-02-15 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n updated this revision to Diff 497596.
xen0n added a comment.

Rebase and change to lower the op in LoongArchAsmPrinter so as to make people's 
lives easier when they come to rebase D141785 
 on top of this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141785/new/

https://reviews.llvm.org/D141785

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/fpatchable-function-entry.c
  clang/test/Sema/patchable-function-entry-attr.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
  llvm/test/CodeGen/LoongArch/patchable-function-entry.ll

Index: llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
@@ -0,0 +1,63 @@
+;; Test the function attribute "patchable-function-entry".
+;; Adapted from the RISCV test case.
+; RUN: llc --mtriple=loongarch32 < %s | FileCheck %s --check-prefixes=CHECK,LA32
+; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s --check-prefixes=CHECK,LA64
+
+define void @f0() "patchable-function-entry"="0" {
+; CHECK-LABEL: f0:
+; CHECK-NEXT:  .Lfunc_begin0:
+; CHECK-NOT: nop
+; CHECK: ret
+; CHECK-NOT:   .section __patchable_function_entries
+  ret void
+}
+
+define void @f1() "patchable-function-entry"="1" {
+; CHECK-LABEL: f1:
+; CHECK-NEXT: .Lfunc_begin1:
+; CHECK: nop
+; CHECK-NEXT:ret
+; CHECK:   .section __patchable_function_entries,"awo",@progbits,f1{{$}}
+; LA32:.p2align 2
+; LA32-NEXT:   .word .Lfunc_begin1
+; LA64:.p2align 3
+; LA64-NEXT:   .dword .Lfunc_begin1
+  ret void
+}
+
+$f5 = comdat any
+define void @f5() "patchable-function-entry"="5" comdat {
+; CHECK-LABEL:   f5:
+; CHECK-NEXT:.Lfunc_begin2:
+; CHECK-COUNT-5:   nop
+; CHECK-NEXT:  ret
+; CHECK: .section __patchable_function_entries,"aGwo",@progbits,f5,comdat,f5{{$}}
+; LA32:  .p2align 2
+; LA32-NEXT: .word .Lfunc_begin2
+; LA64:  .p2align 3
+; LA64-NEXT: .dword .Lfunc_begin2
+  ret void
+}
+
+;; -fpatchable-function-entry=3,2
+;; "patchable-function-prefix" emits data before the function entry label.
+define void @f3_2() "patchable-function-entry"="1" "patchable-function-prefix"="2" {
+; CHECK-LABEL:   .type f3_2,@function
+; CHECK-NEXT:.Ltmp0: # @f3_2
+; CHECK-COUNT-2:   nop
+; CHECK-NEXT:f3_2:
+; CHECK: # %bb.0:
+; CHECK-NEXT:  nop
+; LA32-NEXT:   addi.w $sp, $sp, -16
+; LA64-NEXT:   addi.d $sp, $sp, -16
+;; .size does not include the prefix.
+; CHECK:  .Lfunc_end3:
+; CHECK-NEXT: .size f3_2, .Lfunc_end3-f3_2
+; CHECK:  .section __patchable_function_entries,"awo",@progbits,f3_2{{$}}
+; LA32:   .p2align 2
+; LA32-NEXT:  .word .Ltmp0
+; LA64:   .p2align 3
+; LA64-NEXT:  .dword .Ltmp0
+  %frame = alloca i8, i32 16
+  ret void
+}
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
===
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
@@ -27,6 +27,8 @@
 public:
   explicit LoongArchInstrInfo(LoongArchSubtarget &STI);
 
+  MCInst getNop() const override;
+
   void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
const DebugLoc &DL, MCRegister DstReg, MCRegister SrcReg,
bool KillSrc) const override;
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
===
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
@@ -17,6 +17,7 @@
 #include "MCTargetDesc/LoongArchMCTargetDesc.h"
 #include "MCTargetDesc/LoongArchMatInt.h"
 #include "llvm/CodeGen/RegisterScavenging.h"
+#include "llvm/MC/MCInstBuilder.h"
 
 using namespace llvm;
 
@@ -28,6 +29,13 @@
 LoongArch::ADJCALLSTACKUP),
   STI(STI) {}
 
+MCInst LoongArchInstrInfo::getNop() const {
+  return MCInstBuilder(LoongArch::ANDI)
+  .addReg(LoongArch::R0)
+  .addReg(LoongArch::R0)
+  .addImm(0);
+}
+
 void LoongArchInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
  MachineBasicBlock::iterator MBBI,
  const DebugLoc &DL, MCRegister DstReg,
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
===
--- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
+++ llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
@@ -41,6 +41,8 @@
   bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
  const char *

[PATCH] D141785: [Clang][LoongArch] Implement patchable function entry

2023-02-15 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n updated this revision to Diff 497598.
xen0n added a comment.

Document the change in Clang release note.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141785/new/

https://reviews.llvm.org/D141785

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/fpatchable-function-entry.c
  clang/test/Sema/patchable-function-entry-attr.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
  llvm/test/CodeGen/LoongArch/patchable-function-entry.ll

Index: llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/patchable-function-entry.ll
@@ -0,0 +1,63 @@
+;; Test the function attribute "patchable-function-entry".
+;; Adapted from the RISCV test case.
+; RUN: llc --mtriple=loongarch32 < %s | FileCheck %s --check-prefixes=CHECK,LA32
+; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s --check-prefixes=CHECK,LA64
+
+define void @f0() "patchable-function-entry"="0" {
+; CHECK-LABEL: f0:
+; CHECK-NEXT:  .Lfunc_begin0:
+; CHECK-NOT: nop
+; CHECK: ret
+; CHECK-NOT:   .section __patchable_function_entries
+  ret void
+}
+
+define void @f1() "patchable-function-entry"="1" {
+; CHECK-LABEL: f1:
+; CHECK-NEXT: .Lfunc_begin1:
+; CHECK: nop
+; CHECK-NEXT:ret
+; CHECK:   .section __patchable_function_entries,"awo",@progbits,f1{{$}}
+; LA32:.p2align 2
+; LA32-NEXT:   .word .Lfunc_begin1
+; LA64:.p2align 3
+; LA64-NEXT:   .dword .Lfunc_begin1
+  ret void
+}
+
+$f5 = comdat any
+define void @f5() "patchable-function-entry"="5" comdat {
+; CHECK-LABEL:   f5:
+; CHECK-NEXT:.Lfunc_begin2:
+; CHECK-COUNT-5:   nop
+; CHECK-NEXT:  ret
+; CHECK: .section __patchable_function_entries,"aGwo",@progbits,f5,comdat,f5{{$}}
+; LA32:  .p2align 2
+; LA32-NEXT: .word .Lfunc_begin2
+; LA64:  .p2align 3
+; LA64-NEXT: .dword .Lfunc_begin2
+  ret void
+}
+
+;; -fpatchable-function-entry=3,2
+;; "patchable-function-prefix" emits data before the function entry label.
+define void @f3_2() "patchable-function-entry"="1" "patchable-function-prefix"="2" {
+; CHECK-LABEL:   .type f3_2,@function
+; CHECK-NEXT:.Ltmp0: # @f3_2
+; CHECK-COUNT-2:   nop
+; CHECK-NEXT:f3_2:
+; CHECK: # %bb.0:
+; CHECK-NEXT:  nop
+; LA32-NEXT:   addi.w $sp, $sp, -16
+; LA64-NEXT:   addi.d $sp, $sp, -16
+;; .size does not include the prefix.
+; CHECK:  .Lfunc_end3:
+; CHECK-NEXT: .size f3_2, .Lfunc_end3-f3_2
+; CHECK:  .section __patchable_function_entries,"awo",@progbits,f3_2{{$}}
+; LA32:   .p2align 2
+; LA32-NEXT:  .word .Ltmp0
+; LA64:   .p2align 3
+; LA64-NEXT:  .dword .Ltmp0
+  %frame = alloca i8, i32 16
+  ret void
+}
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
===
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
@@ -27,6 +27,8 @@
 public:
   explicit LoongArchInstrInfo(LoongArchSubtarget &STI);
 
+  MCInst getNop() const override;
+
   void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
const DebugLoc &DL, MCRegister DstReg, MCRegister SrcReg,
bool KillSrc) const override;
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
===
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
@@ -17,6 +17,7 @@
 #include "MCTargetDesc/LoongArchMCTargetDesc.h"
 #include "MCTargetDesc/LoongArchMatInt.h"
 #include "llvm/CodeGen/RegisterScavenging.h"
+#include "llvm/MC/MCInstBuilder.h"
 
 using namespace llvm;
 
@@ -28,6 +29,13 @@
 LoongArch::ADJCALLSTACKUP),
   STI(STI) {}
 
+MCInst LoongArchInstrInfo::getNop() const {
+  return MCInstBuilder(LoongArch::ANDI)
+  .addReg(LoongArch::R0)
+  .addReg(LoongArch::R0)
+  .addImm(0);
+}
+
 void LoongArchInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
  MachineBasicBlock::iterator MBBI,
  const DebugLoc &DL, MCRegister DstReg,
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
===
--- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
+++ llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
@@ -41,6 +41,8 @@
   bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
  const char *ExtraCode, raw_ostream &OS) override;
 
+  void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
+
 

[PATCH] D149946: [LoongArch] Define `ual` feature and override `allowsMisalignedMemoryAccesses`

2023-05-06 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

From a LoongArch developer's perspective, it may be better to only enable UAL 
for LA464 and other supporting models, instead of for the generic `loongarch64` 
model too. This is because although all server- and desktop-class LoongArch 
models have UAL, the embedded-class (Loongson-1 and Loongson-2 series' older 
models) doesn't, and some of them e.g. Loongson 2K1000LA are readily available 
on the market so they're arguably relevant. We don't want to generate 
misaligned memory accesses for those systems only to fall back to much slower 
emulation later.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149946/new/

https://reviews.llvm.org/D149946

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


[PATCH] D150089: [LoongArch] Support fcc* (condition flag) registers in inlineasm clobbers

2023-05-08 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.

It's confirmed offline that LA32 also has 8 `$fcc`'s, so the existing 
assumption holds, and the code changes are correct. (Apparently the "LA32 
Reduced" subset is not supported right now, which only has one `$fcc0`.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150089/new/

https://reviews.llvm.org/D150089

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


[PATCH] D136436: [Clang][LoongArch] Add GPR alias handling without `$` prefix

2023-05-11 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

LGTM now, thanks for updating this patch!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136436/new/

https://reviews.llvm.org/D136436

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


[PATCH] D142688: [Clang][Driver] Handle LoongArch multiarch tuples

2023-04-19 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added inline comments.



Comment at: clang/test/Driver/linux-header-search.cpp:247
 //
+// Check header search on Debian loong64
+// RUN: %clang -### %s -fsyntax-only 2>&1 \

SixWeining wrote:
> Better to use “loongarch64” when talking about debian? Refer 
> https://wiki.debian.org/Multiarch/Tuples
It's the dpkg arch identifier and actually [[ 
https://wiki.debian.org/Ports/loong64 | the port's official name ]]. I chose it 
because it's shorter. Do we still want to emphasize the target tuple instead of 
the distro identity in this case?



Comment at: clang/test/Driver/linux-header-search.cpp:252
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-LOONG64-GNU %s
+//

SixWeining wrote:
> Use LA64 instead of LOONG64?
Similarly I meant to refer to the Debian port name here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142688/new/

https://reviews.llvm.org/D142688

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


[PATCH] D136436: [Clang][LoongArch] Add register alias handling without `$` prefix

2023-05-02 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

Hi, any update on this? Given the `$`-less style has been long established at 
this time, and present in released GCC versions, it seems we indeed have to 
follow suit (and later make GCC accept ABI names for FPRs too). It will also 
make the ClangBuiltLinux work easier.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136436/new/

https://reviews.llvm.org/D136436

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


[PATCH] D139288: [Clang][LoongArch] Add intrinsic for csrrd, csrwr and csrxchg

2022-12-04 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

You'll also need the IOCSR intrinsics too for building Linux. Since they're 
very similar to some of the CSR intrinsics you added here, do you plan to add 
support for them later here or in a separate follow-up change?




Comment at: clang/lib/Headers/larchintrin.h:84
+
+#ifdef __loongarch_grlen == 64
+#define __csrrd_d(/*ui14*/ _1) 
\

Did you actually test this? ;-)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139288/new/

https://reviews.llvm.org/D139288

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


[PATCH] D139686: [lsan] Add lsan support for loongarch64

2022-12-08 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added inline comments.



Comment at: compiler-rt/lib/lsan/lsan_common.cpp:281
+#  elif defined(__loongarch_lp64)
+  return ((p >> 47) == 0);
 #  else

Since our VM layout is actually flexible, would it be better to document this, 
like "Support only the most common VM layout on LoongArch that allows 47 bits 
of user-space VMA"? Exact wording could be optimized, I'm only describing the 
gist here.



Comment at: compiler-rt/test/asan/TestCases/Linux/leak_check_segv.cpp:4
 // REQUIRES: leak-detection
-#include 
+#include 
 #include 

Why unnecessarily reorder things, especially putting this //in front of// the 
standard library includes?



Comment at: compiler-rt/test/asan/TestCases/Linux/leak_check_segv.cpp:20-21
+   16 * 1024, PROT_NONE);
+  mprotect((void *)(((unsigned long)data + kPageSize - 1) & ~(kPageSize - 1)),
+   16 * 1024, PROT_NONE);
   __lsan_do_leak_check();

Might be better to split this part of change out of the LoongArch enablement 
patch after all...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139686/new/

https://reviews.llvm.org/D139686

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


[PATCH] D139612: [Clang][LoongArch] Add intrinsic for iocsrrd and iocsrwr

2022-12-08 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

This should be good enough (reminiscent of CSR ops) but let's wait for other 
reviewers.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139612/new/

https://reviews.llvm.org/D139612

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


[PATCH] D139686: [lsan] Add lsan support for loongarch64

2022-12-08 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added inline comments.



Comment at: compiler-rt/lib/lsan/lsan_common.cpp:281
+#  elif defined(__loongarch_lp64)
+  return ((p >> 47) == 0);
 #  else

tangyouling wrote:
> xen0n wrote:
> > Since our VM layout is actually flexible, would it be better to document 
> > this, like "Support only the most common VM layout on LoongArch that allows 
> > 47 bits of user-space VMA"? Exact wording could be optimized, I'm only 
> > describing the gist here.
> > Since our VM layout is actually flexible, would it be better to document 
> > this, like "Support only the most common VM layout on LoongArch that allows 
> > 47 bits of user-space VMA"? Exact wording could be optimized, I'm only 
> > describing the gist here.
> 
> How about "Allow 47-bit user-space VMA at current"?
"at present"; if you plan to revisit this later for properly supporting 
variable VM layouts, omitting the justification is fine to me.



Comment at: compiler-rt/test/asan/TestCases/Linux/leak_check_segv.cpp:4
 // REQUIRES: leak-detection
-#include 
+#include 
 #include 

tangyouling wrote:
> xen0n wrote:
> > Why unnecessarily reorder things, especially putting this //in front of// 
> > the standard library includes?
> > Why unnecessarily reorder things, especially putting this //in front of// 
> > the standard library includes?
> 
> An automatic adjustment of the format.
So you mean you're actually unable to avoid this diff damage?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139686/new/

https://reviews.llvm.org/D139686

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


[PATCH] D139915: [Clang][LoongArch] Add intrinsic for asrtle, asrtgt, lddir, ldpte and cpucfg

2022-12-12 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

Linux only requires `__cpucfg` among the ones you just added. Please amend the 
patch summary so it's more accurate.

Otherwise LGTM, thanks!




Comment at: llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp:797
+ASRT_LE_GT_CASE(asrtle_d)
+ASRT_LE_GT_CASE(asrtgt_d)
+  case Intrinsic::loongarch_ldpte_d: {

`#undef ASRT_LE_GT_CASE` afterwards?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139915/new/

https://reviews.llvm.org/D139915

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