From: Weining Lu Date: Thu, 13 Oct 2022 06:37:53 +0000 (+0800) Subject: [Clang][LoongArch] Pass "f" and "d" features to cc1 to enable hard float X-Git-Tag: upstream/17.0.6~30698 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fcce2562c177f0ad2aa03620be8675bef5c631d1;p=platform%2Fupstream%2Fllvm.git [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. --- diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp index f8cda26..d364a2e 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 &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 a128e61..eb09419 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 &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 83023a1..15f4527 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 0000000..833ee4f --- /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; +}