[llvm] [LoongArch] Enable all -target-abi options (PR #92222)

via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 03:15:19 PDT 2024


https://github.com/wangleiat updated https://github.com/llvm/llvm-project/pull/92222

>From 1a5a404335044aa997b3c3307b60185fde43c5a3 Mon Sep 17 00:00:00 2001
From: wanglei <wanglei at loongson.cn>
Date: Wed, 15 May 2024 15:23:36 +0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 .../LoongArch/LoongArchISelLowering.cpp       |  5 +--
 .../MCTargetDesc/LoongArchBaseInfo.cpp        | 39 +++++++++++++++++--
 llvm/test/CodeGen/LoongArch/target-abi.ll     | 26 +++++++++++++
 3 files changed, 63 insertions(+), 7 deletions(-)
 create mode 100644 llvm/test/CodeGen/LoongArch/target-abi.ll

diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 21d520656091c..6740563b90b45 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -3575,15 +3575,14 @@ static bool CC_LoongArch(const DataLayout &DL, LoongArchABI::ABI ABI,
   switch (ABI) {
   default:
     llvm_unreachable("Unexpected ABI");
-  case LoongArchABI::ABI_ILP32S:
+    break;
   case LoongArchABI::ABI_ILP32F:
   case LoongArchABI::ABI_LP64F:
-    report_fatal_error("Unimplemented ABI");
-    break;
   case LoongArchABI::ABI_ILP32D:
   case LoongArchABI::ABI_LP64D:
     UseGPRForFloat = !IsFixed;
     break;
+  case LoongArchABI::ABI_ILP32S:
   case LoongArchABI::ABI_LP64S:
     break;
   }
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp
index 928adb03f0989..7fd2526a57c94 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp
@@ -14,6 +14,7 @@
 #include "LoongArchBaseInfo.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/MC/MCSubtargetInfo.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Triple.h"
 
@@ -21,6 +22,36 @@ namespace llvm {
 
 namespace LoongArchABI {
 
+// Check if ABI has been standardized; issue a warning if it hasn't.
+// FIXME: Once all ABIs are standardized, this will be removed.
+static ABI checkABIStandardized(ABI Abi) {
+  bool IsStandardized = false;
+  StringRef ABIName;
+  switch (Abi) {
+  case ABI_ILP32S:
+    ABIName = "ilp32s";
+    break;
+  case ABI_ILP32F:
+    ABIName = "ilp32f";
+    break;
+  case ABI_ILP32D:
+    ABIName = "ilp32d";
+    break;
+  case ABI_LP64F:
+    ABIName = "lp64f";
+    break;
+  case ABI_LP64S:
+  case ABI_LP64D:
+    IsStandardized = true;
+    break;
+  default:
+    llvm_unreachable("");
+  }
+  if (!IsStandardized)
+    errs() << "warning: '" << ABIName << "' has not been standardized\n";
+  return Abi;
+}
+
 ABI computeTargetABI(const Triple &TT, StringRef ABIName) {
   ABI ArgProvidedABI = getTargetABI(ABIName);
   bool Is64Bit = TT.isArch64Bit();
@@ -50,7 +81,7 @@ ABI computeTargetABI(const Triple &TT, StringRef ABIName) {
       errs() << "'" << ABIName
              << "' is not a recognized ABI for this target, ignoring and using "
                 "triple-implied ABI\n";
-    return TripleABI;
+    return checkABIStandardized(TripleABI);
 
   case LoongArchABI::ABI_ILP32S:
   case LoongArchABI::ABI_ILP32F:
@@ -58,7 +89,7 @@ ABI computeTargetABI(const Triple &TT, StringRef ABIName) {
     if (Is64Bit) {
       errs() << "32-bit ABIs are not supported for 64-bit targets, ignoring "
                 "target-abi and using triple-implied ABI\n";
-      return TripleABI;
+      return checkABIStandardized(TripleABI);
     }
     break;
 
@@ -68,7 +99,7 @@ ABI computeTargetABI(const Triple &TT, StringRef ABIName) {
     if (!Is64Bit) {
       errs() << "64-bit ABIs are not supported for 32-bit targets, ignoring "
                 "target-abi and using triple-implied ABI\n";
-      return TripleABI;
+      return checkABIStandardized(TripleABI);
     }
     break;
   }
@@ -77,7 +108,7 @@ ABI computeTargetABI(const Triple &TT, StringRef ABIName) {
     errs() << "warning: triple-implied ABI conflicts with provided target-abi '"
            << ABIName << "', using target-abi\n";
 
-  return ArgProvidedABI;
+  return checkABIStandardized(ArgProvidedABI);
 }
 
 ABI getTargetABI(StringRef ABIName) {
diff --git a/llvm/test/CodeGen/LoongArch/target-abi.ll b/llvm/test/CodeGen/LoongArch/target-abi.ll
new file mode 100644
index 0000000000000..de834c152b180
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/target-abi.ll
@@ -0,0 +1,26 @@
+; RUN: llc --mtriple=loongarch32 --mattr=+d --target-abi=ilp32s < %s 2>&1 \
+; RUN:   | FileCheck %s -DABI=ilp32s --check-prefixes=CHECK,WARNING
+; RUN: llc --mtriple=loongarch32 --mattr=+d --target-abi=ilp32f < %s 2>&1 \
+; RUN:   | FileCheck %s -DABI=ilp32f --check-prefixes=CHECK,WARNING
+; RUN: llc --mtriple=loongarch32 --mattr=+d --target-abi=ilp32d < %s 2>&1 \
+; RUN:   | FileCheck %s -DABI=ilp32d --check-prefixes=CHECK,WARNING
+; RUN: llc --mtriple=loongarch64 --mattr=+d --target-abi=lp64f < %s 2>&1 \
+; RUN:   | FileCheck %s -DABI=lp64f --check-prefixes=CHECK,WARNING
+
+; RUN: llc --mtriple=loongarch64 --mattr=+d --target-abi=lp64s < %s 2>&1 \
+; RUN:   | FileCheck %s --check-prefixes=CHECK,NO-WARNING
+; RUN: llc --mtriple=loongarch64 --mattr=+d --target-abi=lp64d < %s 2>&1 \
+; RUN:   | FileCheck %s --check-prefixes=CHECK,NO-WARNING
+
+;; Check if the ABI has been standardized; issue a warning if it hasn't.
+
+; WARNING: warning: '[[ABI]]' has not been standardized
+
+; NO-WARNING-NOT: warning
+
+define void @nothing() nounwind {
+; CHECK-LABEL: nothing:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:  ret
+  ret void
+}

>From 98cd084aed8c839408c759413d1ba3367e1b8c68 Mon Sep 17 00:00:00 2001
From: wanglei <wanglei at loongson.cn>
Date: Wed, 15 May 2024 18:15:08 +0800
Subject: [PATCH 2/2] simpler code, address @xen0n's comment

Created using spr 1.3.5-bogner
---
 .../Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp    | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp
index 7fd2526a57c94..6d75e575cd3cf 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp
@@ -25,7 +25,6 @@ namespace LoongArchABI {
 // Check if ABI has been standardized; issue a warning if it hasn't.
 // FIXME: Once all ABIs are standardized, this will be removed.
 static ABI checkABIStandardized(ABI Abi) {
-  bool IsStandardized = false;
   StringRef ABIName;
   switch (Abi) {
   case ABI_ILP32S:
@@ -42,13 +41,11 @@ static ABI checkABIStandardized(ABI Abi) {
     break;
   case ABI_LP64S:
   case ABI_LP64D:
-    IsStandardized = true;
-    break;
+    return Abi;
   default:
     llvm_unreachable("");
   }
-  if (!IsStandardized)
-    errs() << "warning: '" << ABIName << "' has not been standardized\n";
+  errs() << "warning: '" << ABIName << "' has not been standardized\n";
   return Abi;
 }
 



More information about the llvm-commits mailing list