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

WÁNG Xuěruì via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 31 17:36:07 PST 2023


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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142688.493796.patch
Type: text/x-patch
Size: 3393 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230201/f6b6931b/attachment-0001.bin>


More information about the cfe-commits mailing list