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

via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 00:24:18 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-loongarch

Author: wanglei (wangleiat)

<details>
<summary>Changes</summary>

This is a pre-commit for modifying `computeTargetABI` logic.

This patch will provide warning prompts when using those ABIs that have
not yet been standardized.


---
Full diff: https://github.com/llvm/llvm-project/pull/92222.diff


3 Files Affected:

- (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp (+2-3) 
- (modified) llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp (+35-4) 
- (added) llvm/test/CodeGen/LoongArch/target-abi.ll (+26) 


``````````diff
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
+}

``````````

</details>


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


More information about the llvm-commits mailing list