[clang] fcce256 - [Clang][LoongArch] Pass "f" and "d" features to cc1 to enable hard float
Weining Lu via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 13 05:04:57 PDT 2022
Author: Weining Lu
Date: 2022-10-13T20:00:29+08:00
New Revision: fcce2562c177f0ad2aa03620be8675bef5c631d1
URL: https://github.com/llvm/llvm-project/commit/fcce2562c177f0ad2aa03620be8675bef5c631d1
DIFF: https://github.com/llvm/llvm-project/commit/fcce2562c177f0ad2aa03620be8675bef5c631d1.diff
LOG: [Clang][LoongArch] Pass "f" and "d" features to cc1 to enable hard float
On LoongArch, currently neither of "f" and "d" feature is passed from
clang driver to cc1 by default. This means the backend generates code
for soft float.
In order to run programs in current LoongArch machines (hard float
environment) this patch temporarily enables "f" and "d" features.
In future, we should conditionally turn on these features depend on
various clang options, e.g. -mdouble-float, -msingle-float,
-msoft-float and -mfpu.
Added:
clang/test/Driver/loongarch-default-features.c
Modified:
clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
clang/lib/Driver/ToolChains/Arch/LoongArch.h
clang/lib/Driver/ToolChains/Clang.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index f8cda26ad3f8e..d364a2e8f7a8e 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -26,3 +26,14 @@ StringRef loongarch::getLoongArchABI(const ArgList &Args,
// TODO: select appropiate ABI.
return Triple.getArch() == llvm::Triple::loongarch32 ? "ilp32d" : "lp64d";
}
+
+void loongarch::getLoongArchTargetFeatures(const Driver &D,
+ const llvm::Triple &Triple,
+ const ArgList &Args,
+ std::vector<StringRef> &Features) {
+ // FIXME: hornor various clang options that may affect target features, e.g.
+ // -march/-mtune/-mdouble-float/-msingle-float/-msoft-float/-mfpu. See:
+ // https://loongson.github.io/LoongArch-Documentation/LoongArch-toolchain-conventions-EN.html
+ Features.push_back("+f");
+ Features.push_back("+d");
+}
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.h b/clang/lib/Driver/ToolChains/Arch/LoongArch.h
index a128e611f8c3c..eb09419c2c1ba 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.h
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.h
@@ -19,6 +19,10 @@ namespace tools {
namespace loongarch {
StringRef getLoongArchABI(const llvm::opt::ArgList &Args,
const llvm::Triple &Triple);
+
+void getLoongArchTargetFeatures(const Driver &D, const llvm::Triple &Triple,
+ const llvm::opt::ArgList &Args,
+ std::vector<llvm::StringRef> &Features);
} // end namespace loongarch
} // end namespace tools
} // end namespace driver
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 83023a155dee9..15f45275b76ab 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -372,6 +372,10 @@ static void getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
case llvm::Triple::csky:
csky::getCSKYTargetFeatures(D, Triple, Args, CmdArgs, Features);
break;
+ case llvm::Triple::loongarch32:
+ case llvm::Triple::loongarch64:
+ loongarch::getLoongArchTargetFeatures(D, Triple, Args, Features);
+ break;
}
for (auto Feature : unifyTargetFeatures(Features)) {
diff --git a/clang/test/Driver/loongarch-default-features.c b/clang/test/Driver/loongarch-default-features.c
new file mode 100644
index 0000000000000..833ee4fd3fafa
--- /dev/null
+++ b/clang/test/Driver/loongarch-default-features.c
@@ -0,0 +1,10 @@
+// RUN: %clang --target=loongarch32 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=LA32
+// RUN: %clang --target=loongarch64 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=LA64
+
+// LA32: "target-features"="+d,+f"
+// LA64: "target-features"="+d,+f"
+
+/// Dummy function
+int foo(void) {
+ return 3;
+}
More information about the cfe-commits
mailing list