Skip to content

Commit

Permalink
[Clang][LoongArch] Pass "f" and "d" features to cc1 to enable hard float
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SixWeining committed Oct 13, 2022
1 parent 48aea4a commit fcce256
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
Expand Up @@ -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");
}
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/Arch/LoongArch.h
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Expand Up @@ -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)) {
Expand Down
10 changes: 10 additions & 0 deletions 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;
}

0 comments on commit fcce256

Please sign in to comment.